From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 804F03B637F for ; Wed, 27 May 2026 20:48:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779914906; cv=none; b=pbfLmQfVlFNH6yp3jo3LkpXToPrDdFr+DFf2HvJo2PQ2svvWO3HrNhFM5URZHpgEWFYia+w2E5Dwk0GOCv8xFvZCEML4DjrAZsLS/ptb9GtQKLBVJ+9AgJHIoV1H/hPlKh6C6XXILqYY2sFPNapZK2IJT2ASjxQISYb0fYgVKyA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779914906; c=relaxed/simple; bh=l5utMigt3ZQHnFSdncqv9s5JEG4L2+Jjugd/3yPMeAo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TVV8MOma+KcFAA1iafknf7PLA8rq7pdbd7ln7ql7ICx3OFUEiOZxN2Ol/berHPvKW8SGQcLA7XoEPiWR6y3uWrBDBAIWr3XDyrQo5Y2BigLpftaexDIzIZe2bXSS+HVdIIyJ5bO0CFany2msGydITKsKUkYetDHmttiBSX3DLcw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org; spf=pass smtp.mailfrom=cmpxchg.org; dkim=pass (2048-bit key) header.d=cmpxchg.org header.i=@cmpxchg.org header.b=cbV/DC5v; arc=none smtp.client-ip=209.85.222.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg.org header.i=@cmpxchg.org header.b="cbV/DC5v" Received: by mail-qk1-f182.google.com with SMTP id af79cd13be357-91173f20ccdso539464385a.0 for ; Wed, 27 May 2026 13:48:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg.org; s=google; t=1779914901; x=1780519701; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=B4EOQagJ0AFWLKeiqsu95H2CZJTRs9F1Y/QS2dFLRqc=; b=cbV/DC5v+IpAs92+MCZxGBOmglWChdoH+QI93I2+2BRDcmeAewQN31l4VkD1mswSGY p3zS7NsiJU+N+i0azB/mlU/hhjh2owlnrqjoPDlP+v/BxhXjCJiYOaKzpjxtX7OKL0JH V9w3z4CzpzdTmrDbll5zByIUQ4BdtTASGz0+TUG5SqBYU2S57Uh0sKTWVAY5uIi5CP98 TtHyApApfykaplIucc/g8BKTFcwWMfhgfgYQtvcHwvpE6wnqdjzQnVSlIrm2+JhIFFA5 KeokoPBQkBma8n+PJyGxIl506d+x1gTTww4/Ifp59ntM0KYoLrI2mxS0bSglF/aR8tYw CJXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779914901; x=1780519701; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=B4EOQagJ0AFWLKeiqsu95H2CZJTRs9F1Y/QS2dFLRqc=; b=kGTgi/VArYLF+kw/HDVYktwDsKJuCnNB/5pbD9IH6xT0f7E9yWDoUSod0SW3HPivQ5 HRkWzUbsjIcjelWPyDjU7fuIQPLyXk1yHuFndCEqoxD4bOJOrETKP6WQXGNDaKyrk6KM okoA2NyImqKPgNv4nYS211woctqOgQObYTYhjGF+Fxl3cOScKXp8wLkZ75kHYBD6fVYn W0eW96nNZN76nLJHdzBbQSoAuu6SgU0bT0ggNPoYE6X8PTq8SK+9wNhT207814qV/CrJ 19ujuYlx4FoPLim+5Txg1sysGpwxZOD14TQbXLxnus6XdEMLNUACo4QtKw7h/iIXMBgh hhhA== X-Forwarded-Encrypted: i=1; AFNElJ/fBLGXE1xREZpLzkEMCZ/7WU0Un8ezjGQ0EjhTVPkSV4qtmyD1p/vYV7yb7ltNfFBhjnZ6F9kGMsb4bxw=@vger.kernel.org X-Gm-Message-State: AOJu0YzpMzmZoOjihEWWMY/rTHmrKYa6SrdvV6DtRxL/Kn+qm0Sj+Ixb sV+0w8oRHIOiaSSwdQNu8ZoD90VEVHTmHeIeYRjijrTw0F/viTHQQjgIY7SsJYqyDX8= X-Gm-Gg: Acq92OH6JbURhUViPZTUwvuxeuIFrSl3RgFS1IWy3jxCoj0NKKGi3GiktIuoKDiE6rI DvLlMfEnjrHqvp0BB9ypUpSuLy4r5GrF2KSQ79ngChTrHkI6f9OK9b/geayjgz88hAq21rYYGWz lUChwzqwjAx1BV87ntLQCpKg9dMf28MxgJ1TQhI9iGbopvkHqr9KpqO7ReSf7V330t0mAssxvEh VeabV/uSGXsn354fiktrEFLllCtqzIQPwtBr8Vh20wOXdsVIszsdMrZ9mpMZOo3p5Y26BUF1/pj rb6YcQaxZGE8yVgRRjMJqFdHcHNYv9OeLoUDy/VzTewpv3ZxBUU/vgZPHxaB9QYaB7EevL+4jR6 SJmdkmJZUcBRAs1sCNu6MJ1UdJlCvDvJHnUAsanIrev/s8dj19pd/jfsXr21h8PBq7F0kcV4riQ aNGgov+Rs6F04BjCtG3o3U1m1ugqlTdqE5 X-Received: by 2002:a05:620a:4408:b0:902:eacc:bf88 with SMTP id af79cd13be357-914b4a19480mr3620622585a.62.1779914900580; Wed, 27 May 2026 13:48:20 -0700 (PDT) Received: from localhost ([2603:7001:f100:500:365a:60ff:fe62:ff29]) by smtp.gmail.com with ESMTPSA id af79cd13be357-914f8810a50sm601500585a.41.2026.05.27.13.48.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2026 13:48:19 -0700 (PDT) From: Johannes Weiner To: Andrew Morton Cc: David Hildenbrand , Lorenzo Stoakes , Shakeel Butt , Michal Hocko , Dave Chinner , Roman Gushchin , Muchun Song , Qi Zheng , Yosry Ahmed , Zi Yan , "Liam R . Howlett" , Usama Arif , Kiryl Shutsemau , Vlastimil Babka , Kairui Song , Mikhail Zaslonko , Vasily Gorbik , Baolin Wang , Barry Song , Dev Jain , Lance Yang , Nico Pache , Ryan Roberts , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 8/9] mm: memory: flatten alloc_anon_folio() retry loop Date: Wed, 27 May 2026 16:45:15 -0400 Message-ID: <20260527204757.2544958-9-hannes@cmpxchg.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260527204757.2544958-1-hannes@cmpxchg.org> References: <20260527204757.2544958-1-hannes@cmpxchg.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit alloc_anon_folio() uses a top-level if (folio) that buries the success path four levels deep. This makes for awkward long lines and wrapping. The next patch will add more code here, so flatten this now to keep things clean and simple. The next label is already there, use it for !folio. No functional change intended. Suggested-by: Lorenzo Stoakes (Oracle) Signed-off-by: Johannes Weiner Acked-by: Usama Arif Acked-by: Shakeel Butt --- mm/memory.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 7c020995eafc..135f5c0f57bd 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5215,24 +5215,24 @@ static struct folio *alloc_anon_folio(struct vm_fault *vmf) while (orders) { addr = ALIGN_DOWN(vmf->address, PAGE_SIZE << order); folio = vma_alloc_folio(gfp, order, vma, addr); - if (folio) { - if (mem_cgroup_charge(folio, vma->vm_mm, gfp)) { - count_mthp_stat(order, MTHP_STAT_ANON_FAULT_FALLBACK_CHARGE); - folio_put(folio); - goto next; - } - folio_throttle_swaprate(folio, gfp); - /* - * When a folio is not zeroed during allocation - * (__GFP_ZERO not used) or user folios require special - * handling, folio_zero_user() is used to make sure - * that the page corresponding to the faulting address - * will be hot in the cache after zeroing. - */ - if (user_alloc_needs_zeroing()) - folio_zero_user(folio, vmf->address); - return folio; + if (!folio) + goto next; + if (mem_cgroup_charge(folio, vma->vm_mm, gfp)) { + count_mthp_stat(order, MTHP_STAT_ANON_FAULT_FALLBACK_CHARGE); + folio_put(folio); + goto next; } + folio_throttle_swaprate(folio, gfp); + /* + * When a folio is not zeroed during allocation + * (__GFP_ZERO not used) or user folios require special + * handling, folio_zero_user() is used to make sure + * that the page corresponding to the faulting address + * will be hot in the cache after zeroing. + */ + if (user_alloc_needs_zeroing()) + folio_zero_user(folio, vmf->address); + return folio; next: count_mthp_stat(order, MTHP_STAT_ANON_FAULT_FALLBACK); order = next_order(&orders, order); -- 2.54.0