From patchwork Thu Jul 20 07:08:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13319866 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9A45EB64DC for ; Thu, 20 Jul 2023 07:08:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 416762800BD; Thu, 20 Jul 2023 03:08:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3280528004C; Thu, 20 Jul 2023 03:08:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0DF0A2800BD; Thu, 20 Jul 2023 03:08:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id E1DF028004C for ; Thu, 20 Jul 2023 03:08:34 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B3AFEC0196 for ; Thu, 20 Jul 2023 07:08:34 +0000 (UTC) X-FDA: 81031112148.23.23DDD99 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf20.hostedemail.com (Postfix) with ESMTP id C46F61C002B for ; Thu, 20 Jul 2023 07:08:32 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=1DoBmPRp; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf20.hostedemail.com: domain of 3b924ZAoKCDoukonuWdiaZckkcha.Ykihejqt-iigrWYg.knc@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3b924ZAoKCDoukonuWdiaZckkcha.Ykihejqt-iigrWYg.knc@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689836912; a=rsa-sha256; cv=none; b=vcn0sYAYqmWL3TlL5XU91iwBYPexBRJU9hDdp+gmp7qtN4z10KVnm9hH8rjaKuZBZm+Vx2 Sr0RggkSpREl8VuoXCiI08r/q/7JftOIdlYf7JhQ7kYetJx78vKoYjbQIFPSfVotlaGniB 3XL0mo/5B9XCC+dKF61tOKhixgBmPKY= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=1DoBmPRp; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf20.hostedemail.com: domain of 3b924ZAoKCDoukonuWdiaZckkcha.Ykihejqt-iigrWYg.knc@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3b924ZAoKCDoukonuWdiaZckkcha.Ykihejqt-iigrWYg.knc@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689836912; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GTtTsHYHZoypkh/ZbOFrb+97cNaIZGVMYPTBvEUZ8QA=; b=ZnZZ+Eak7ZOZUwox6s1SQzHzqHqUq/Ovm5mGoDwiJZhMxOgy8WYVIz23CwH1bRfYm/4DjK g5EAjS0U31hXUt7USKLeQeUJPSYKhaWa3mYyeSLMEXyd9ceWgEgIyJAsPkWwcn0jaEPRmH +YoywdwL6pSIJiKZbt4SqAW5hEQDt+s= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-c4cda9d3823so421545276.1 for ; Thu, 20 Jul 2023 00:08:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689836912; x=1692428912; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=GTtTsHYHZoypkh/ZbOFrb+97cNaIZGVMYPTBvEUZ8QA=; b=1DoBmPRpqoKxp5AI1ATOavPZeo0Whgkd5Tc59Swf0g3JyV+Sf4czsw5vt5hRV/iIWU m0gxZI0ZpwmKuzcQe6n8ABa+pR3RNfGEwG4M79yda3Vq21aVBJ/g7QPw4WwY0KIttAPP qZs11I8hXcrNiTzcuVsx+5sSznkYJ5ijPhs+K2QY4AKhJ+1OPsJskvfvc2riuWl1X0pr fjY+rxKO1ypRGpwy/gVhyEiUbivpXGQsHDrV1rAgXPICZpfqdKSn1Khg2rXXV4x7hO0B V/yFis6Q3bBvFsNeipAISnXIhdf4e5y1csYuoWKJL9e1bvfMGj/AyzmZSyj99NVp9/vT 61xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689836912; x=1692428912; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GTtTsHYHZoypkh/ZbOFrb+97cNaIZGVMYPTBvEUZ8QA=; b=a4YzMxGVWfpEax1R8jZUHA2BRB2CMESwvF2LbNQQKwTNJcGrjRPJy4HhxApayUWZQo uZmcViRA2x/h9zTX+iIsvPDnzDP3NkwcJxmQTsQ68oz6tCfmLKRnWhc00je9YcPX9HAT DIFTKEIXYlx/kQDH3v0FyLHvJZaP+ipeCfuedC98qPPkxybTrzFtA+6ucR7Gb4Igx0iL Nua7srf4L2fPjvMiOeOATJHM21tiNlZOH93p0X0uqkYPqHfqJXvBbuRJlm7FUaVJwnno Cj/rcRKHJlvU6SvNovcGh267TyPYAGHwR2mdja8p1MJx+Sja765PIo7uq/k586rgEzXC B94A== X-Gm-Message-State: ABy/qLY458EkQzyd3xzSN8mOER1gh3qZityHUYEuM43+2mpf5AAGiRj2 gxfB1a0+kbDiNe2gzQh2V85yeDSMi7/d6TXD X-Google-Smtp-Source: APBJJlFLKOPz8aT2ynaMGRvS7LvS60oh3DFyuJzygEiZuz8hLCEZV4fcd2R5Eiopcv2P65Ha4e5fn/ebih6t3IaU X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a25:53c4:0:b0:c6e:fe1a:3657 with SMTP id h187-20020a2553c4000000b00c6efe1a3657mr38214ybb.3.1689836911707; Thu, 20 Jul 2023 00:08:31 -0700 (PDT) Date: Thu, 20 Jul 2023 07:08:19 +0000 In-Reply-To: <20230720070825.992023-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20230720070825.992023-1-yosryahmed@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230720070825.992023-3-yosryahmed@google.com> Subject: [RFC PATCH 2/8] mm: vmscan: add lruvec_for_each_list() helper From: Yosry Ahmed To: Andrew Morton , Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt Cc: Muchun Song , "Matthew Wilcox (Oracle)" , Tejun Heo , Zefan Li , Yu Zhao , Luis Chamberlain , Kees Cook , Iurii Zaikin , "T.J. Mercier" , Greg Thelen , linux-kernel@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org, Yosry Ahmed X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: C46F61C002B X-Stat-Signature: 7srz1jsjdekf6p1csss5ty6njobu49a6 X-HE-Tag: 1689836912-176847 X-HE-Meta: U2FsdGVkX191Ie5XKPQHf0SPdzoJOs1nkgd1DI+IZz3s8qDA8PqKZcNdsxyZaNnLrzFsSj7JUFQz+V1VS7i+5plfG0IcMJHHC7nnz346CEi7YrdkIJ4/4re/R8+FB/7Jo2Lv25KFX5rDqxhbQ9dIDBC+88z0uKFJq5Z6Ws1LIfCWDbwwp/YfY7onqwURSfuJrg58eF5gd9V4Yahuj6L4HDWk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Uu9uF6wq08ZYbDrvdbtDCNeT4yLY/jxPne/4qYryc+MoDD0NVd0eWXdLLerR/7S9wQxyBBwPEhHQFp1A2kiSuqap79WBwWjcNks3OjWsLaB6VZrWsFzpLPeutaVCP2AVxlSk/8YoXH5qxhdVBT+WQCYBRyttCDpvoPfG67ZEb4wzXoAch8Ci71LUFNzWX43wNF5I2UKU/DqP4NJZjHNADJvRHQhiaA1Av5jSu7nU2fstwZwAdyMD5ZjUCQqqum5I/Vm18+feufxobwEH1UGTncnA0S/X/cRAazNtmhnRGwz+3K0Ci1XcBkxAvh85Rm8Jnd3uAyWIjWA3GImHhw3IWR3NKFO+64PHFqubxPpb1BypDTZL4wh7NQKGzmFZZh4IIIYwstaEItBw8gyg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This helper is used to provide a callback to be called for each lruvec list. This abstracts different lruvec implementations (MGLRU vs. classic LRUs). The helper is used by a following commit to iterate all folios in all LRUs lists for memcg recharging. Signed-off-by: Yosry Ahmed --- include/linux/swap.h | 8 ++++++++ mm/vmscan.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/linux/swap.h b/include/linux/swap.h index 456546443f1f..c0621deceb03 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -406,6 +406,14 @@ extern void lru_cache_add_inactive_or_unevictable(struct page *page, struct vm_area_struct *vma); /* linux/mm/vmscan.c */ +typedef bool (*lruvec_list_fn_t)(struct lruvec *lruvec, + struct list_head *list, + enum lru_list lru, + void *arg); +extern void lruvec_for_each_list(struct lruvec *lruvec, + lruvec_list_fn_t fn, + void *arg); + extern unsigned long zone_reclaimable_pages(struct zone *zone); extern unsigned long try_to_free_pages(struct zonelist *zonelist, int order, gfp_t gfp_mask, nodemask_t *mask); diff --git a/mm/vmscan.c b/mm/vmscan.c index 1080209a568b..e7956000a3b6 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -6254,6 +6254,34 @@ static void lru_gen_shrink_node(struct pglist_data *pgdat, struct scan_control * #endif /* CONFIG_LRU_GEN */ +/* + * lruvec_for_each_list - make a callback for every folio list in the lruvec + * @lruvec: the lruvec to iterate lists in + * @fn: the callback to make for each list, iteration stops if it returns true + * @arg: argument to pass to @fn + */ +void lruvec_for_each_list(struct lruvec *lruvec, lruvec_list_fn_t fn, void *arg) +{ + enum lru_list lru; + +#ifdef CONFIG_LRU_GEN + if (lru_gen_enabled()) { + int gen, type, zone; + + for_each_gen_type_zone(gen, type, zone) { + lru = type * LRU_INACTIVE_FILE; + if (fn(lruvec, &lruvec->lrugen.folios[gen][type][zone], + lru, arg)) + break; + } + } else +#endif + for_each_evictable_lru(lru) { + if (fn(lruvec, &lruvec->lists[lru], lru, arg)) + break; + } +} + static void shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc) { unsigned long nr[NR_LRU_LISTS];