Skip to contentSkip to conversation

fs: mpage: account cgroup ownership after the folio is added to the bio

PATCH New Xavier Xia 1 participant 1 message Dec 4 VFS

lore
Share & tools
lore

Xavier Xia

author
#0 lore raw

PATCH 1/1 fs: mpage: account cgroup ownership after the folio is added to the bio

mpage_write_folio() accounts the folio before trying to add it to the bio. When bio_add_folio() fails, the bio is submitted and the folio is retried from alloc_new, which accounts the same folio again. A folio that needs several attempts is therefore counted several times in the round's cgroup ownership arbitration.

Account the folio after bio_add_folio() succeeded. Failed attempts no longer contribute, successful ones contribute exactly once, and the bio submission order is unchanged.

---
 fs/mpage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/mpage.c +1 -1
index f02d8ebd72af..acf18cb8f342 100644
@@ -607,12 +607,12 @@ static int mpage_write_folio(struct writeback_control *wbc, struct folio *folio,
 	 * the confused fail path above (OOM) will be very confused when
 	 * it finds all bh marked clean (i.e. it will not write anything)
 	 */
-	wbc_account_cgroup_owner(wbc, folio, folio_size(folio));
 	length = first_unmapped << blkbits;
 	if (!bio_add_folio(bio, folio, length, 0)) {
 		bio = mpage_bio_submit_write(bio);
 		goto alloc_new;
 	}
+	wbc_account_cgroup_owner(wbc, folio, folio_size(folio));
 
 	clean_buffers(folio, first_unmapped);