Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

netfs: Use a folio_queue allocation and free functions

Provide and use folio_queue allocation and free functions to combine the
allocation, initialisation and stat (un)accounting steps that are repeated
in several places.

Signed-off-by: David Howells <dhowells@redhat.com>
Link: https://lore.kernel.org/r/20241216204124.3752367-4-dhowells@redhat.com
cc: Jeff Layton <jlayton@kernel.org>
cc: netfs@lists.linux.dev
cc: linux-fsdevel@vger.kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

David Howells and committed by
Christian Brauner
eb118159 2a8a3846

+42 -13
+3 -9
fs/netfs/buffered_read.c
··· 131 131 struct folio_queue *tail = rreq->buffer_tail, *new; 132 132 size_t added; 133 133 134 - new = kmalloc(sizeof(*new), GFP_NOFS); 134 + new = netfs_folioq_alloc(GFP_NOFS); 135 135 if (!new) 136 136 return -ENOMEM; 137 - netfs_stat(&netfs_n_folioq); 138 - folioq_init(new); 139 137 new->prev = tail; 140 138 tail->next = new; 141 139 rreq->buffer_tail = new; ··· 361 363 struct folio_batch put_batch; 362 364 size_t added; 363 365 364 - folioq = kmalloc(sizeof(*folioq), GFP_KERNEL); 366 + folioq = netfs_folioq_alloc(GFP_KERNEL); 365 367 if (!folioq) 366 368 return -ENOMEM; 367 - netfs_stat(&netfs_n_folioq); 368 - folioq_init(folioq); 369 369 rreq->buffer = folioq; 370 370 rreq->buffer_tail = folioq; 371 371 rreq->submitted = rreq->start; ··· 436 440 { 437 441 struct folio_queue *folioq; 438 442 439 - folioq = kmalloc(sizeof(*folioq), GFP_KERNEL); 443 + folioq = netfs_folioq_alloc(GFP_KERNEL); 440 444 if (!folioq) 441 445 return -ENOMEM; 442 446 443 - netfs_stat(&netfs_n_folioq); 444 - folioq_init(folioq); 445 447 folioq_append(folioq, folio); 446 448 BUG_ON(folioq_folio(folioq, 0) != folio); 447 449 BUG_ON(folioq_folio_order(folioq, 0) != folio_order(folio));
+34 -4
fs/netfs/misc.c
··· 8 8 #include <linux/swap.h> 9 9 #include "internal.h" 10 10 11 + /** 12 + * netfs_folioq_alloc - Allocate a folio_queue struct 13 + * @gfp: Allocation constraints 14 + * 15 + * Allocate, initialise and account the folio_queue struct. 16 + */ 17 + struct folio_queue *netfs_folioq_alloc(gfp_t gfp) 18 + { 19 + struct folio_queue *fq; 20 + 21 + fq = kmalloc(sizeof(*fq), gfp); 22 + if (fq) { 23 + netfs_stat(&netfs_n_folioq); 24 + folioq_init(fq); 25 + } 26 + return fq; 27 + } 28 + EXPORT_SYMBOL(netfs_folioq_alloc); 29 + 30 + /** 31 + * netfs_folioq_free - Free a folio_queue struct 32 + * @folioq: The object to free 33 + * 34 + * Free and unaccount the folio_queue struct. 35 + */ 36 + void netfs_folioq_free(struct folio_queue *folioq) 37 + { 38 + netfs_stat_d(&netfs_n_folioq); 39 + kfree(folioq); 40 + } 41 + EXPORT_SYMBOL(netfs_folioq_free); 42 + 11 43 /* 12 44 * Make sure there's space in the rolling queue. 13 45 */ ··· 119 87 120 88 if (next) 121 89 next->prev = NULL; 122 - netfs_stat_d(&netfs_n_folioq); 123 - kfree(head); 90 + netfs_folioq_free(head); 124 91 wreq->buffer = next; 125 92 return next; 126 93 } ··· 142 111 folio_put(folio); 143 112 } 144 113 } 145 - netfs_stat_d(&netfs_n_folioq); 146 - kfree(p); 114 + netfs_folioq_free(p); 147 115 } 148 116 } 149 117
+5
include/linux/netfs.h
··· 21 21 22 22 enum netfs_sreq_ref_trace; 23 23 typedef struct mempool_s mempool_t; 24 + struct folio_queue; 24 25 25 26 /** 26 27 * folio_start_private_2 - Start an fscache write on a folio. [DEPRECATED] ··· 453 452 void netfs_end_io_write(struct inode *inode); 454 453 int netfs_start_io_direct(struct inode *inode); 455 454 void netfs_end_io_direct(struct inode *inode); 455 + 456 + /* Miscellaneous APIs. */ 457 + struct folio_queue *netfs_folioq_alloc(gfp_t gfp); 458 + void netfs_folioq_free(struct folio_queue *folioq); 456 459 457 460 /** 458 461 * netfs_inode - Get the netfs inode context from the inode