Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp759680rdb; Thu, 19 Oct 2023 20:14:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHpUkODFuYp2Zm/EbQFaTbp/i0jr3iZoRqQp1nEEt81d8pj9Up2AubVxS555Biz0+fN6/9/ X-Received: by 2002:a17:902:facb:b0:1ca:85ae:3b59 with SMTP id ld11-20020a170902facb00b001ca85ae3b59mr826179plb.9.1697771692372; Thu, 19 Oct 2023 20:14:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697771692; cv=none; d=google.com; s=arc-20160816; b=FSawtuviYSKEVY7A1mpRSpYNAz4N6TdzVLWLkkA+NTtN2gCv6q6DM8nKLW4TsXkvSQ A2aYWM32MAbq3/OI1mArzgZsqnUneaOo2rOi1q1NR85finyAstsp0NkwUX895syRgQS/ EArk0Wo6jG/bTMzweQI8KOKA68/ZxSsYrc7STzOKrq72JKYXT6klbgbjf7g7d/hBYhlz 8IBfzJXlLmwyjkRxu7CgWpR9LY45ljU+9uPERps5bIDUvAEW+KTXTSdLzeNGBr7jIbZq 8KBvr0aNUevgUkwV1lj9YBhTI+iXdloalYLjAJdZtkJJiBdTO+XcXNrkSImgg2WDZ7sj mHeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:dkim-signature; bh=7ywAvwbhJr5/vU0AbBbA2bWEKwNnkjoqCzdwXBcHgIc=; fh=Le3tyKubyU/7RnWwJapNnJa6mYuEQPckzdpE8prpEm8=; b=v9gwdOigujURv9vo77O1R7IZDmREzLoClSzi6wq0ahRZcJXDPbe86XSuZF0a8k1Fwg 1L9qJv+tGA/WmasbNcQG57jPMkiT09RtPCOed+kdF2czMy7ONQdpSK99E9prCYlUKjgc K2aVJUwAiWPhBBUYq1l4mcRIa59yuiH3vTwmP7Aikn0dFPsyFGo+GXCT+3lc+oZa6ben 7tpgUFVimUT/HD0kVvdOphaMradnWJbLyx14biEPFXtroswi0o2PU8KgQaN6M7gTVSBn cZm2Pe3VN2Wh3QM+sVezZRjxTu4kVSIpaJFYAHsRejZU4HE6e7UPBLE9921jcn8mUcr6 TmLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nLksk7IG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id v3-20020a170902b7c300b001c61bd9db5csi795585plz.317.2023.10.19.20.14.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 20:14:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nLksk7IG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 543B482958BD; Thu, 19 Oct 2023 20:14:51 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346886AbjJTDOe (ORCPT + 99 others); Thu, 19 Oct 2023 23:14:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233427AbjJTDOd (ORCPT ); Thu, 19 Oct 2023 23:14:33 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B1711A3 for ; Thu, 19 Oct 2023 20:14:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697771671; x=1729307671; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=J+9tE2sdyUVhhpIhll2eZHkIf4yz1uC4SXuiNuD7B+s=; b=nLksk7IGg4/fKkOag4xEqbKM7qg73PmZZIZdq4hGQA2Hla05n0QJ+0Kr /w4P01kySYuaZVvTWqGOyPBzg7A5gzsjswtCypJjI35LprJIocpXND/fu fQnoG246VgiK/G9raIKO/PLNE4DQ6eKha6J11YD50WWHqy+v3r3Wi0T2t 96CL6N2VPRhcDkbfiTC9RoY08lJ61Qv2Nh5IweLEek4GusS4+xhtuK2z3 dHNRWQ0Rdd8xAO2dHxQlb8veH0JaEn4mJq1HhSryW1AIKlTw5GbbL6Vat bCYCeSYM9TxQRYiDOmnOCNQHJbKunBn2jD5uP/5z8mmfxloIWSW7ANe3g g==; X-IronPort-AV: E=McAfee;i="6600,9927,10868"; a="452899356" X-IronPort-AV: E=Sophos;i="6.03,238,1694761200"; d="scan'208";a="452899356" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Oct 2023 20:14:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10868"; a="1004468457" X-IronPort-AV: E=Sophos;i="6.03,238,1694761200"; d="scan'208";a="1004468457" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Oct 2023 20:14:26 -0700 From: "Huang, Ying" To: Ryan Roberts Cc: Andrew Morton , David Hildenbrand , Matthew Wilcox , Gao Xiang , Yu Zhao , Yang Shi , Michal Hocko , Kefeng Wang , , , Tim Chen Subject: Re: [PATCH v2 2/2] mm: swap: Swap-out small-sized THP without splitting In-Reply-To: <4b351eaa-c2db-408b-9ce2-4b12e3d6b30a@arm.com> (Ryan Roberts's message of "Thu, 19 Oct 2023 15:25:39 +0100") References: <20231017161302.2518826-1-ryan.roberts@arm.com> <20231017161302.2518826-3-ryan.roberts@arm.com> <87r0ls773p.fsf@yhuang6-desk2.ccr.corp.intel.com> <87mswfuppr.fsf@yhuang6-desk2.ccr.corp.intel.com> <4b351eaa-c2db-408b-9ce2-4b12e3d6b30a@arm.com> Date: Fri, 20 Oct 2023 11:12:24 +0800 Message-ID: <87sf66f0mf.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 19 Oct 2023 20:14:51 -0700 (PDT) Ryan Roberts writes: > On 19/10/2023 06:49, Huang, Ying wrote: >> Ryan Roberts writes: >> >>> On 18/10/2023 07:55, Huang, Ying wrote: >>>> Ryan Roberts writes: >>>> >> >> [snip] >> >>>>> diff --git a/include/linux/swap.h b/include/linux/swap.h >>>>> index a073366a227c..35cbbe6509a9 100644 >>>>> --- a/include/linux/swap.h >>>>> +++ b/include/linux/swap.h >>>>> @@ -268,6 +268,12 @@ struct swap_cluster_info { >>>>> struct percpu_cluster { >>>>> struct swap_cluster_info index; /* Current cluster index */ >>>>> unsigned int next; /* Likely next allocation offset */ >>>>> + unsigned int large_next[]; /* >>>>> + * next free offset within current >>>>> + * allocation cluster for large folios, >>>>> + * or UINT_MAX if no current cluster. >>>>> + * Index is (order - 1). >>>>> + */ >>>>> }; >>>>> >>>>> struct swap_cluster_list { >>>>> diff --git a/mm/swapfile.c b/mm/swapfile.c >>>>> index b83ad77e04c0..625964e53c22 100644 >>>>> --- a/mm/swapfile.c >>>>> +++ b/mm/swapfile.c >>>>> @@ -987,35 +987,70 @@ static int scan_swap_map_slots(struct swap_info_struct *si, >>>>> return n_ret; >>>>> } >>>>> >>>>> -static int swap_alloc_cluster(struct swap_info_struct *si, swp_entry_t *slot) >>>>> +static int swap_alloc_large(struct swap_info_struct *si, swp_entry_t *slot, >>>>> + unsigned int nr_pages) >>>> >>>> This looks hacky. IMO, we should put the allocation logic inside >>>> percpu_cluster framework. If percpu_cluster framework doesn't work for >>>> you, just refactor it firstly. >>> >>> I'm not sure I really understand what you are suggesting - could you elaborate? >>> What "framework"? I only see a per-cpu data structure and >>> scan_swap_map_try_ssd_cluster(), which is very much geared towards order-0 >>> allocations. >> >> I suggest to share as much code as possible between order-0 and order > >> 0 swap entry allocation. I think that we can make >> scan_swap_map_try_ssd_cluster() works for order > 0 swap entry allocation. >> > > [...] > >>>>> + /* >>>>> + * If scan_swap_map_slots() can't find a free cluster, it will >>>>> + * check si->swap_map directly. To make sure this standby >>>>> + * cluster isn't taken by scan_swap_map_slots(), mark the swap >>>>> + * entries bad (occupied). (same approach as discard). >>>>> + */ >>>>> + memset(si->swap_map + offset + nr_pages, SWAP_MAP_BAD, >>>>> + SWAPFILE_CLUSTER - nr_pages); >>>> >>>> There's an issue with this solution. If the free space of swap device >>>> runs low, it's possible that >>>> >>>> - some cluster are put in the percpu_cluster of some CPUs >>>> the swap entries there are marked as used >>>> >>>> - no free swap entries elsewhere >>>> >>>> - nr_swap_pages isn't 0 >>>> >>>> So, we will still scan LRU, but swap allocation fails, although there's >>>> still free swap space. > > I'd like to decide how best to solve this problem before I can figure out how > much code sharing I can do for the order-0 vs order > 0 allocators. > > I see a couple of potential options: > > 1) Manipulate nr_swap_pages to include the entries that are marked SWAP_MAP_BAD, > so when reserving a new per-order/per-cpu cluster, subtract SWAPFILE_CLUSTER, > and then add nr_pages for each allocation from that cluster. > > 2) Don't mark the entries in the reserved cluster as SWAP_MAP_BAD, which would > allow the scanner to steal (order-0) entries. The scanner could set a flag in > the cluster info to mark it as having been allocated from by the scanner, so the > next attempt to allocate a high order from it would cause discarding it as the > cpu's current cluster and trying to get a fresh cluster from the free list. > > While option 2 is a bit more complex, I prefer it as a solution. What do you think? I think that this is a good choice to start with. We may build more optimization on top of it if necessary. -- Best Regards, Huang, Ying