From patchwork Thu Jul 12 23:36:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 10522423 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 B46B46032C for ; Thu, 12 Jul 2018 23:37:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A513B298A6 for ; Thu, 12 Jul 2018 23:37:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 990B22991D; Thu, 12 Jul 2018 23:37:18 +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 35931298A6 for ; Thu, 12 Jul 2018 23:37:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EC8286B0010; Thu, 12 Jul 2018 19:37:07 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C9EF96B0266; Thu, 12 Jul 2018 19:37:07 -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 8F94A6B026B; Thu, 12 Jul 2018 19:37:07 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f197.google.com (mail-pf0-f197.google.com [209.85.192.197]) by kanga.kvack.org (Postfix) with ESMTP id 35A826B026A for ; Thu, 12 Jul 2018 19:37:07 -0400 (EDT) Received: by mail-pf0-f197.google.com with SMTP id i123-v6so11421644pfc.13 for ; Thu, 12 Jul 2018 16:37:07 -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=h8I2/xQ57A8UoHJUJwgk0g7HLFux+8Vrw4gnYr7dQ8I=; b=FU1nwmHCWnRUkc1iE6JtXc9Tt68d6Kg7ptiTW0dZwQqULO9V0q5wvatE8npxiuMvw1 f/Mp2YLC3kHY1s1CNmBtFRW5/M+fcaNzPc7/injpLcr/vNhqoqWiviMMvB3CsKJ99n8n +RBH5qph4l9Yt1KDOauXRg4VJ6R5tmdlIJNVHoqJGsV7lTuGW86Wxl5/bV0PqMcvxsZs REgziyBRxJ4ExNpVJHiYd6bdcbui/+kNDU9+SK5oCTZFT3l+9Y6CF2/+kDBCrXBelINo lWnKM4beucG/haFgkDe0wYF2CFu244TqCK214iBK1Gu/Bcg37DrhaKpfU0yFKtLEaQBM ER2Q== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 192.55.52.151 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: AOUpUlGs9q+U3jloZwssSK9VNPvuNbdGHUhlVRUpNc+BYySNGlPMOz17 Cxw0KnJ/lQBSafoe5/DmbnYxnHUjzAmuCYYFUvdZkKcQuTPlG7ccPZvWqiGBgmFGqLDdK1vJySZ hfJgPn2kRqCJm1iG/VBBqkqGBGewU+c2em91gplDVxRj9n8KiAPfOoQvjqK0t2SeZ7Q== X-Received: by 2002:a63:bd01:: with SMTP id a1-v6mr3856071pgf.319.1531438626898; Thu, 12 Jul 2018 16:37:06 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc/riayzAmlbF09CuvwCx739DPvFk4Z+uSKFpPzfZvk9raH12m0gmEIyRFOhhL+fEsk/woW X-Received: by 2002:a63:bd01:: with SMTP id a1-v6mr3856041pgf.319.1531438626143; Thu, 12 Jul 2018 16:37:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531438626; cv=none; d=google.com; s=arc-20160816; b=BqueJ5YqZ3rHw+xRpnlVW5cLKRItJnwLmoprogFGceeFjL4M6O7gKZv6HxTSXHpcdI GPlLjjTFanwZxS0SGsspSej4w9MSKtMvkDp5KWJ+/MBFTghgXpGfe2gMZbVGAG5RIkUK KMzfhQO9KJnKGoPaX4T2nFOA9DvNBcA4BQ3sHsmpPL4wzGcQHguo1H9FVdYyMBEAkvHe 4Fh6YHqKQaLwbnLq5Grszp2O0438i3lZJ+/1QFi2vQBsfeOfc8bEpEOmSH5h1AyCgsfD 4ALQQSw2qz6vZDFLjPmcqlyDQQZEIfNFaQh7G3IiC201khK+Y2JWWppS8yLQP9XOJGaQ jaGw== 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=h8I2/xQ57A8UoHJUJwgk0g7HLFux+8Vrw4gnYr7dQ8I=; b=ycaYXryoAcAmSJp6muTIsEZxB3vMf0FmPI7AwdKmWA8m3qs1V1z9h+qeGJ+1QKOH0E oYZCrchK6xwzd8lviJK8giorxlh+bvynGfSrrmnCCLnZzeQIkUbw1gDMwjJ/BIU4zwno l3Rro1ThCYLlFdy4bhCdjvIdQBmH+DYUzTX57VxtBSo8j2hxYwZmk/Xlewk6yq1DLTpw CSssKEkXMHb+QWRUP02q1EfPpBGEux8k7fybxzmx2BXFACFD7JuMy5lnthETXhv6JURg iidFnHYduzE/LLIvACQlORK/YWB7h3wayI1bUzLjnMZUI0rW7acnTG+pWaJ9IxuKfsFA AouQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 192.55.52.151 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga17.intel.com (mga17.intel.com. [192.55.52.151]) by mx.google.com with ESMTPS id v14-v6si19305318pga.270.2018.07.12.16.37.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Jul 2018 16:37:06 -0700 (PDT) Received-SPF: pass (google.com: domain of ying.huang@intel.com designates 192.55.52.151 as permitted sender) client-ip=192.55.52.151; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 192.55.52.151 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 orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Jul 2018 16:37:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,345,1526367600"; d="scan'208";a="57272313" Received: from yongjuns-mobl2.ccr.corp.intel.com (HELO yhuang6-ux31a.ccr.corp.intel.com) ([10.254.213.67]) by orsmga006.jf.intel.com with ESMTP; 12 Jul 2018 16:36:58 -0700 From: "Huang, Ying" To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Dave Hansen , Michal Hocko , Johannes Weiner , Shaohua Li , Hugh Dickins , Minchan Kim , Rik van Riel , Daniel Jordan , Dan Williams Subject: [PATCH 6/6] swap, put_swap_page: Share more between huge/normal code path Date: Fri, 13 Jul 2018 07:36:36 +0800 Message-Id: <20180712233636.20629-7-ying.huang@intel.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180712233636.20629-1-ying.huang@intel.com> References: <20180712233636.20629-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 From: Huang Ying In this patch, locking related code is shared between huge/normal code path in put_swap_page() to reduce code duplication. And `free_entries == 0` case is merged into more general `free_entries != SWAPFILE_CLUSTER` case, because the new locking method makes it easy. The added lines is same as the removed lines. But the code size is increased when CONFIG_TRANSPARENT_HUGEPAGE=n. text data bss dec hex filename base: 24215 2028 340 26583 67d7 mm/swapfile.o unified: 24577 2028 340 26945 6941 mm/swapfile.o Signed-off-by: "Huang, Ying" Cc: Dave Hansen Cc: Michal Hocko Cc: Johannes Weiner Cc: Shaohua Li Cc: Hugh Dickins Cc: Minchan Kim Cc: Rik van Riel Cc: Daniel Jordan Cc: Dan Williams --- mm/swapfile.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index bc488bf36c86..17dce780b4c8 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1280,8 +1280,8 @@ void put_swap_page(struct page *page, swp_entry_t entry) if (!si) return; + ci = lock_cluster_or_swap_info(si, offset); if (nr == SWAPFILE_CLUSTER) { - ci = lock_cluster(si, offset); VM_BUG_ON(!cluster_is_huge(ci)); map = si->swap_map + offset; for (i = 0; i < SWAPFILE_CLUSTER; i++) { @@ -1290,13 +1290,9 @@ void put_swap_page(struct page *page, swp_entry_t entry) if (val == SWAP_HAS_CACHE) free_entries++; } - if (!free_entries) { - for (i = 0; i < SWAPFILE_CLUSTER; i++) - map[i] &= ~SWAP_HAS_CACHE; - } cluster_clear_huge(ci); - unlock_cluster(ci); if (free_entries == SWAPFILE_CLUSTER) { + unlock_cluster_or_swap_info(si, ci); spin_lock(&si->lock); ci = lock_cluster(si, offset); memset(map, 0, SWAPFILE_CLUSTER); @@ -1307,12 +1303,16 @@ void put_swap_page(struct page *page, swp_entry_t entry) return; } } - if (nr == 1 || free_entries) { - for (i = 0; i < nr; i++, entry.val++) { - if (!__swap_entry_free(si, entry, SWAP_HAS_CACHE)) - free_swap_slot(entry); + for (i = 0; i < nr; i++, entry.val++) { + if (!__swap_entry_free_locked(si, offset + i, SWAP_HAS_CACHE)) { + unlock_cluster_or_swap_info(si, ci); + free_swap_slot(entry); + if (i == nr - 1) + return; + lock_cluster_or_swap_info(si, offset); } } + unlock_cluster_or_swap_info(si, ci); } #ifdef CONFIG_THP_SWAP