From patchwork Thu Jul 19 08:48:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 10533905 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6CE5A603B5 for ; Thu, 19 Jul 2018 08:49:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D3D3295DB for ; Thu, 19 Jul 2018 08:49:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 510C5295E1; Thu, 19 Jul 2018 08:49:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C0A3A295DB for ; Thu, 19 Jul 2018 08:49:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BFA5F6B027B; Thu, 19 Jul 2018 04:49:06 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B577C6B027C; Thu, 19 Jul 2018 04:49:06 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9126A6B027D; Thu, 19 Jul 2018 04:49:06 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by kanga.kvack.org (Postfix) with ESMTP id 43D0E6B027B for ; Thu, 19 Jul 2018 04:49:06 -0400 (EDT) Received: by mail-pg1-f199.google.com with SMTP id n5-v6so3320213pgp.20 for ; Thu, 19 Jul 2018 01:49:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=FEsw7GfA4Ydhn9/kzZ8UNwpV9v8QbpOXyJZ10czrDk8=; b=i46GAWV6eP3bO6XfzXD9kAiwV20C+CzQsCHy7hQbz7wvsrWUeIDTRx7rJybN2d6t2V gyij7xMQhQ4Apvx6xWETlkBD2jFH3wLpRpU3KVZ5UtpHON/UoxExPbOkK43y86ohce9u C+YVqzYfrTbaQVdS3hY+kxR1z3jZikp70jRtJwq2SktzRNgwftZcLnHp0MMF5y71XYGL UCrvFoLwmZWdnBi5o3EarwJ9WPH3z1IT4WFq6zity9kaxD/5Q0zUQJkD7cHkTBMYzHep U30ThG3UC2V+iB0ncZkbIiC80bwQIQEpMC6E8mWR7s/IkVyoTjPC4kM/VQZENkjhDe0z nL8g== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: AOUpUlH21EBXCSM1wtSl/hF7L/h4rIpQpr5I9yHdcVr1aeik4te3gxZd 6xRI9qxtME7nxTXHEXnGjLJ71+laAdD3uvhZxzHhKEQEbVn+x+L8jq9zImg8aGU3ZlkAPqzQ0Oa IIqC4TrRDYVWbDC3T9PEU8eBULxP7C6PCTq1YT8/5Z/9fLpLkoHVTZ8cmCwxrmPQaJw== X-Received: by 2002:a63:2b15:: with SMTP id r21-v6mr9303253pgr.262.1531990145946; Thu, 19 Jul 2018 01:49:05 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeuxcp59f+ti9nlm0vSERdExaFK61Fc6ZnMndl333VaK88RvlMus2osoGBDDt3NvLEyG/E1 X-Received: by 2002:a63:2b15:: with SMTP id r21-v6mr9303199pgr.262.1531990145148; Thu, 19 Jul 2018 01:49:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531990145; cv=none; d=google.com; s=arc-20160816; b=s2Xth8QJ4PKrTAn1xpF98WK5kyaWtkmo3e301REiic+MmXjvNPkfMkSnNqW7a3+pAN Ags8qo33EEWAldgDKxloMWAD0SdYvd3vjfJMz3tD1/MM/3QbWfunBiCvo4LimXDGkGbu KEpv8ciCQXGZ5Y0Vkuj3iQQHp7a951NMOGJq3nAVQHUk+i209wjD+0x7pU0QQGWMDbj1 29OVl9r8AClUlaa7b1+Vi/Jn86j5zTYFJENo4TEhvqNMiftCEK5H9wR7PudFcdt5XEdJ fzFWmeITan7u4E2Bx96Yg13UpcekGbN2N/N1ZeK16U3nRMY3B3qlsNk0+ZRsQ0H62QQ+ DlKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=FEsw7GfA4Ydhn9/kzZ8UNwpV9v8QbpOXyJZ10czrDk8=; b=WPZaK8nsZeMpxTzBKcGftKeiJ65Q7hVn44eRKHT8YWIcUCJDXitifqPCYTTjA1Zaao 3oQhWfaQT2727Up1la8U00JO2I0cYY1VBaGAl2/eB+Ddaly/uQlLDiK2dfyh4S9PmjLd 4NZ++i7dhAIzkMJbakGQDtY6jkOShu4pB8Yvl3DDmQsGxu1eesxvBm6Wv+w7uhwPD35g iqPqy3cpuELHz8mHtFf+mooxQ9ZbpYmbdI4KZ/q/SokCrFPisJ/eCFlO5CwGEycFptiw 7LR2MkO4yU22dNUiWnpDHV32mDQUOvbo+o1CcVDlIrXkEVirnr5wlegRsc3xMGXNWEUM hYvA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga07.intel.com (mga07.intel.com. [134.134.136.100]) by mx.google.com with ESMTPS id x18-v6si4948122pll.193.2018.07.19.01.49.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 01:49:05 -0700 (PDT) Received-SPF: pass (google.com: domain of ying.huang@intel.com designates 134.134.136.100 as permitted sender) client-ip=134.134.136.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Jul 2018 01:49:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,374,1526367600"; d="scan'208";a="76038316" Received: from yhuang6-ux31a.sh.intel.com ([10.239.195.246]) by orsmga002.jf.intel.com with ESMTP; 19 Jul 2018 01:49:02 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Daniel Jordan , Dave Hansen , Michal Hocko , Johannes Weiner , Shaohua Li , Hugh Dickins , Minchan Kim , Rik van Riel , Dan Williams Subject: [PATCH v3 6/8] swap, get_swap_pages: Use entry_size instead of cluster in parameter Date: Thu, 19 Jul 2018 16:48:40 +0800 Message-Id: <20180719084842.11385-7-ying.huang@intel.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180719084842.11385-1-ying.huang@intel.com> References: <20180719084842.11385-1-ying.huang@intel.com> 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: X-Virus-Scanned: ClamAV using ClamSMTP As suggested by Matthew Wilcox, it is better to use "int entry_size" instead of "bool cluster" as parameter to specify whether to operate for huge or normal swap entries. Because this improve the flexibility to support other swap entry size. And Dave Hansen thinks that this improves code readability too. So in this patch, the "bool cluster" parameter of get_swap_pages() is replaced by "int entry_size". And nr_swap_entries() trick is used to reduce the binary size when !CONFIG_TRANSPARENT_HUGE_PAGE. text data bss dec hex filename base 24215 2028 340 26583 67d7 mm/swapfile.o head 24123 2004 340 26467 6763 mm/swapfile.o Signed-off-by: "Huang, Ying" Cc: Daniel Jordan Cc: Dave Hansen Cc: Michal Hocko Cc: Johannes Weiner Cc: Shaohua Li Cc: Hugh Dickins Cc: Minchan Kim Cc: Rik van Riel Cc: Dan Williams --- include/linux/swap.h | 2 +- mm/swap_slots.c | 8 ++++---- mm/swapfile.c | 16 ++++++++-------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index e20c240d6c65..34de0d8bf4fa 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -443,7 +443,7 @@ 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, bool cluster, swp_entry_t swp_entries[]); +extern int get_swap_pages(int n, swp_entry_t swp_entries[], int entry_size); 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 008ccb22fee6..63a7b4563a57 100644 --- a/mm/swap_slots.c +++ b/mm/swap_slots.c @@ -269,8 +269,8 @@ 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, false, - cache->slots); + cache->nr = get_swap_pages(SWAP_SLOTS_CACHE_SIZE, + cache->slots, 1); return cache->nr; } @@ -316,7 +316,7 @@ swp_entry_t get_swap_page(struct page *page) if (PageTransHuge(page)) { if (IS_ENABLED(CONFIG_THP_SWAP)) - get_swap_pages(1, true, &entry); + get_swap_pages(1, &entry, HPAGE_PMD_NR); goto out; } @@ -350,7 +350,7 @@ swp_entry_t get_swap_page(struct page *page) goto out; } - get_swap_pages(1, false, &entry); + get_swap_pages(1, &entry, 1); 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 407f97287ab3..318ceb527c78 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -943,18 +943,18 @@ static unsigned long scan_swap_map(struct swap_info_struct *si, } -int get_swap_pages(int n_goal, bool cluster, swp_entry_t swp_entries[]) +int get_swap_pages(int n_goal, swp_entry_t swp_entries[], int entry_size) { - unsigned long nr_pages = cluster ? SWAPFILE_CLUSTER : 1; + 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 && cluster); + WARN_ON_ONCE(n_goal > 1 && size == SWAPFILE_CLUSTER); - avail_pgs = atomic_long_read(&nr_swap_pages) / nr_pages; + avail_pgs = atomic_long_read(&nr_swap_pages) / size; if (avail_pgs <= 0) goto noswap; @@ -964,7 +964,7 @@ int get_swap_pages(int n_goal, bool cluster, swp_entry_t swp_entries[]) if (n_goal > avail_pgs) n_goal = avail_pgs; - atomic_long_sub(n_goal * nr_pages, &nr_swap_pages); + atomic_long_sub(n_goal * size, &nr_swap_pages); spin_lock(&swap_avail_lock); @@ -991,14 +991,14 @@ int get_swap_pages(int n_goal, bool cluster, swp_entry_t swp_entries[]) spin_unlock(&si->lock); goto nextsi; } - if (cluster) { + if (size == SWAPFILE_CLUSTER) { if (!(si->flags & SWP_FILE)) n_ret = swap_alloc_cluster(si, swp_entries); } else n_ret = scan_swap_map_slots(si, SWAP_HAS_CACHE, n_goal, swp_entries); spin_unlock(&si->lock); - if (n_ret || cluster) + if (n_ret || size == SWAPFILE_CLUSTER) goto check_out; pr_debug("scan_swap_map of si %d failed to find offset\n", si->type); @@ -1024,7 +1024,7 @@ int get_swap_pages(int n_goal, bool cluster, swp_entry_t swp_entries[]) check_out: if (n_ret < n_goal) - atomic_long_add((long)(n_goal - n_ret) * nr_pages, + atomic_long_add((long)(n_goal - n_ret) * size, &nr_swap_pages); noswap: return n_ret;