From mboxrd@z Thu Jan 1 00:00:00 1970 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 7209CC433F5 for ; Thu, 7 Apr 2022 17:37:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AEF5D6B0071; Thu, 7 Apr 2022 13:37:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A78866B0073; Thu, 7 Apr 2022 13:37:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9192D6B0074; Thu, 7 Apr 2022 13:37:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0254.hostedemail.com [216.40.44.254]) by kanga.kvack.org (Postfix) with ESMTP id 8128D6B0071 for ; Thu, 7 Apr 2022 13:37:17 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 3C8298248076 for ; Thu, 7 Apr 2022 17:37:07 +0000 (UTC) X-FDA: 79330788894.25.55484FB Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) by imf24.hostedemail.com (Postfix) with ESMTP id AB208180002 for ; Thu, 7 Apr 2022 17:37:06 +0000 (UTC) Received: by mail-pg1-f175.google.com with SMTP id c2so5518764pga.10 for ; Thu, 07 Apr 2022 10:37:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=4eRHeyIBtK2JphAWCbOBSoQhEFWtF686Z+g4Q2iefZY=; b=if1xA9KX9VUTDYBy0O1Zbzhz932LFp3+2Z0+M0/iAM1d7aH8Oghn1gsf598e7WzX6E yP9cHjyzH8NAwlk2gZm3hDipOcAcsuk1xpWpOMJdvm05A4Kztodou5S6IQRP0RwCWV2E zQtFut+48Y3CkrBhfBqL2MRLUrq15pR3yX/TBwQ3rr8iuRptW/DxKxWr0i84MfZGfZVQ mJej6gVfgREaKDyjBH7piajMe9slo5nWkD94tXfrRDVUQ+OM3nMSehw1wiXyC7wcxddu oUp+uwT3nVnpPIkubQe6gA1CE5Nk/GNch0uhP6o5bMlvJs2LknYP4IO0UHFhYMCr/23I 338w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=4eRHeyIBtK2JphAWCbOBSoQhEFWtF686Z+g4Q2iefZY=; b=1GFA/ZE+vXRYI9/3PMhuagGB8QdVi/CHYsCeDWqfeNgu2MpMKoWitkvggXG1z6qheM 0MiGqaWZPFkorZHfw46Hkhd7TgZ8cBBAbBsO7fviuU5o10ku94F2d3UdRhsoDjYUjqu6 gZvPa0Ygqhonx6dcJ2NPsINjMuYS8GDMXnEV0H/cVoLp4ROaEn9KVPvtP6aSSpC/WC4L 5Ej697coDi5q0rljZod9lzxMdely+KuvX6zg5qlK3H68xslru/6BwnOyTqy1tAP/G42y wqLl7sMLbnG5QRI63K/UraKwBX68AqdrjXvxy5Y+OhTQ+CFkLova+GJmrSDhCFeMXQJv EZuA== X-Gm-Message-State: AOAM533QPFWPr2klyccFo2weqEgmjpvn0WkA8HYJ4gXnGxybPQzVlV95 45ipMj+dcZ3yO9x0HIcX6Wtn2TP/FpkCBmGD0NQ= X-Google-Smtp-Source: ABdhPJzlAS8hmsxylYW21tU1uJImhTA4zhDVtcCR3MC9HC0ShdzrzYF8a+gHsxc7uFNWNMLBKZgjlplgu2SkBL7uJ/g= X-Received: by 2002:a62:7952:0:b0:4fd:a244:f67b with SMTP id u79-20020a627952000000b004fda244f67bmr15332141pfc.23.1649353025396; Thu, 07 Apr 2022 10:37:05 -0700 (PDT) MIME-Version: 1.0 References: <20220407020953.475626-1-shy828301@gmail.com> In-Reply-To: From: Yang Shi Date: Thu, 7 Apr 2022 10:36:54 -0700 Message-ID: Subject: Re: [PATCH] mm: swap: determine swap device by using page nid To: Aaron Lu Cc: Huang Ying , Andrew Morton , Linux MM , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" X-Rspam-User: X-Stat-Signature: b9pcmq9pi3crwajwxu3k1t4jnfh1xzq6 Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=if1xA9KX; spf=pass (imf24.hostedemail.com: domain of shy828301@gmail.com designates 209.85.215.175 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: AB208180002 X-HE-Tag: 1649353026-577640 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: On Thu, Apr 7, 2022 at 1:12 AM Aaron Lu wrote: > > On Wed, Apr 06, 2022 at 07:09:53PM -0700, Yang Shi wrote: > > The swap devices are linked to per node priority lists, the swap device > > closer to the node has higher priority on that node's priority list. > > This is supposed to improve I/O latency, particularly for some fast > > devices. But the current code gets nid by calling numa_node_id() which > > actually returns the nid that the reclaimer is running on instead of the > > nid that the page belongs to. > > > > Right. > > > Pass the page's nid dow to get_swap_pages() in order to pick up the > > right swap device. But it doesn't work for the swap slots cache which > > is per cpu. We could skip swap slots cache if the current node is not > > the page's node, but it may be overkilling. So keep using the current > > node's swap slots cache. The issue was found by visual code inspection > > so it is not sure how much improvement could be achieved due to lack of > > suitable testing device. But anyway the current code does violate the > > design. > > > > I intentionally used the reclaimer's nid because I think when swapping > out to a device, it is faster when the device is on the same node as > the cpu. OK, the offline discussion with Huang Ying showed the design was to have page's nid in order to achieve better I/O performance (more noticeable on faster devices) since the reclaimer may be running on a different node from the reclaimed page. > > Anyway, I think I can make a test case where the workload allocates all > its memory on the remote node and its workingset memory is larger then > the available memory so swap is triggered, then we can see which way > achieves better performance. Sounds reasonable to you? Yeah, definitely, thank you so much. I don't have a fast enough device by hand to show the difference right now. If you could get some data it would be perfect. BTW, this patch doesn't change the node for swap slots cache, so it may still use the swap device on a remote node if swap slots cache is used. > > > Cc: Huang Ying > > Signed-off-by: Yang Shi > > --- > > include/linux/swap.h | 3 ++- > > mm/swap_slots.c | 7 ++++--- > > mm/swapfile.c | 5 ++--- > > 3 files changed, 8 insertions(+), 7 deletions(-) > > > > diff --git a/include/linux/swap.h b/include/linux/swap.h > > index 27093b477c5f..e442cf6b61ea 100644 > > --- a/include/linux/swap.h > > +++ b/include/linux/swap.h > > @@ -497,7 +497,8 @@ extern void si_swapinfo(struct sysinfo *); > > extern swp_entry_t get_swap_page(struct page *page); > > extern void put_swap_page(struct page *page, swp_entry_t entry); > > extern swp_entry_t get_swap_page_of_type(int); > > -extern int get_swap_pages(int n, swp_entry_t swp_entries[], int entry_size); > > +extern int get_swap_pages(int n, swp_entry_t swp_entries[], int entry_size, > > + int node); > > extern int add_swap_count_continuation(swp_entry_t, gfp_t); > > extern void swap_shmem_alloc(swp_entry_t); > > extern int swap_duplicate(swp_entry_t); > > diff --git a/mm/swap_slots.c b/mm/swap_slots.c > > index 2b5531840583..a1c5cf6a4302 100644 > > --- a/mm/swap_slots.c > > +++ b/mm/swap_slots.c > > @@ -264,7 +264,7 @@ static int refill_swap_slots_cache(struct swap_slots_cache *cache) > > cache->cur = 0; > > if (swap_slot_cache_active) > > cache->nr = get_swap_pages(SWAP_SLOTS_CACHE_SIZE, > > - cache->slots, 1); > > + cache->slots, 1, numa_node_id()); > > > > return cache->nr; > > } > > @@ -305,12 +305,13 @@ swp_entry_t get_swap_page(struct page *page) > > { > > swp_entry_t entry; > > struct swap_slots_cache *cache; > > + int nid = page_to_nid(page); > > > > entry.val = 0; > > > > if (PageTransHuge(page)) { > > if (IS_ENABLED(CONFIG_THP_SWAP)) > > - get_swap_pages(1, &entry, HPAGE_PMD_NR); > > + get_swap_pages(1, &entry, HPAGE_PMD_NR, nid); > > goto out; > > } > > > > @@ -342,7 +343,7 @@ swp_entry_t get_swap_page(struct page *page) > > goto out; > > } > > > > - get_swap_pages(1, &entry, 1); > > + get_swap_pages(1, &entry, 1, nid); > > out: > > if (mem_cgroup_try_charge_swap(page, entry)) { > > put_swap_page(page, entry); > > diff --git a/mm/swapfile.c b/mm/swapfile.c > > index 63c61f8b2611..151fffe0fd60 100644 > > --- a/mm/swapfile.c > > +++ b/mm/swapfile.c > > @@ -1036,13 +1036,13 @@ static void swap_free_cluster(struct swap_info_struct *si, unsigned long idx) > > swap_range_free(si, offset, SWAPFILE_CLUSTER); > > } > > > > -int get_swap_pages(int n_goal, swp_entry_t swp_entries[], int entry_size) > > +int get_swap_pages(int n_goal, swp_entry_t swp_entries[], int entry_size, > > + int node) > > { > > unsigned long size = swap_entry_size(entry_size); > > struct swap_info_struct *si, *next; > > long avail_pgs; > > int n_ret = 0; > > - int node; > > > > /* Only single cluster request supported */ > > WARN_ON_ONCE(n_goal > 1 && size == SWAPFILE_CLUSTER); > > @@ -1060,7 +1060,6 @@ int get_swap_pages(int n_goal, swp_entry_t swp_entries[], int entry_size) > > atomic_long_sub(n_goal * size, &nr_swap_pages); > > > > start_over: > > - node = numa_node_id(); > > plist_for_each_entry_safe(si, next, &swap_avail_heads[node], avail_lists[node]) { > > /* requeue si to after same-priority siblings */ > > plist_requeue(&si->avail_lists[node], &swap_avail_heads[node]); > > -- > > 2.26.3 > > > >