From patchwork Thu Jul 19 08:48:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 10533911 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 4D32160638 for ; Thu, 19 Jul 2018 08:49:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E45F295D9 for ; Thu, 19 Jul 2018 08:49:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 32160295DD; Thu, 19 Jul 2018 08:49:19 +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 AC724295D9 for ; Thu, 19 Jul 2018 08:49:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E1C266B027F; Thu, 19 Jul 2018 04:49:11 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D29616B0281; Thu, 19 Jul 2018 04:49:11 -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 C1BB86B0280; Thu, 19 Jul 2018 04:49:11 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f200.google.com (mail-pf0-f200.google.com [209.85.192.200]) by kanga.kvack.org (Postfix) with ESMTP id 81CA36B027E for ; Thu, 19 Jul 2018 04:49:11 -0400 (EDT) Received: by mail-pf0-f200.google.com with SMTP id u16-v6so3734871pfm.15 for ; Thu, 19 Jul 2018 01:49:11 -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=nd/f6pa2IhVowRp0+NFWbSX5BzT7gm0H8yMvkwyfijM=; b=MgO21QQo1lnHcbCzrEy+uqnmaL9yu8H8XB4nbv4KWX6zrn/+KKyeQnmkAuI7w5khCp OlzF2Z95XxHYrjKBRY577NHfeu1KdW4vBlzilq1svvwy0y60aOv29vRm7AG7B4Rzo6Fb EEE3XAubgnuTbgUmvtNmb/YoYJCQOJ9mpN9qfZQE37e9SOLW0MELdr6JWdexCUHkGGM6 6fTbGbI17nfZbGEhr6Zpanby1w5S7vRVtnaYWsEcc7+HeK+ixyp77XwU9l5ghHjx7A8K 9JOcTDYENnu0fapzuzFl/Yo8thE6R4lWJ5Z6fPIZp1x3eIjzaPaGGtSI0rHTTdGOICF1 IvIg== 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: AOUpUlHru8NBkdUzla+m9eKgZZ304BzirwZ7gzmr/LBwROgtuJo9mSs2 JU+dB7CNYmSQATeQ9ncEGmiRon9zKAmSWtW046Dzr0TvVkdkGj6C46mdk1QJ80sp7xzYQMplpLw /0hBCHoaqIK0+KVsLe210flg2C64tAFRu53lmEz/XuhP3k1T+XUn2Qjb3p0t8dmggug== X-Received: by 2002:a62:384:: with SMTP id 126-v6mr8653314pfd.11.1531990151219; Thu, 19 Jul 2018 01:49:11 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf6eOxpvWYpau/ATdzIW3HhLKu7aDAzEYQNpfdapD9HHMkaTqX/esZJXN2at+lUtmYHsJh3 X-Received: by 2002:a62:384:: with SMTP id 126-v6mr8653252pfd.11.1531990150174; Thu, 19 Jul 2018 01:49:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531990150; cv=none; d=google.com; s=arc-20160816; b=vj25UNyxC1OGd1CLp/LAi8qB7eYjM8dwRPwq7CE2bVP6qNhxh8/k7Ec+PDJ1pCxiwi 7C9F4vh9Yy9x/hxLcXLMss38ZLbg6sld0PO5odni9CYVBKmuqfEJFiisKYJgQFLhUD6r FKCwS3ySYqRNTGSRqDwKGaFGCTFSYDwBtUJFQWa/MCsJtRLiOxlWFHmFV7MnSo4FlnWD kkxsICKqJUgvltOtFFX+KXemz1W/Otdci/oRopYaBzCHx6ZgAwNWlBATeaZmQ83RfhxQ P1zOT/jmJCbmqwNhFRqtGHfUhXTIWbJikAuvabDin+SeeYXwR4i43nlCi5fbIwULwGsS sgLQ== 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=nd/f6pa2IhVowRp0+NFWbSX5BzT7gm0H8yMvkwyfijM=; b=kMCSda9LmrhqL+hNvR2XIiASTBIEXwFgm/FeI+80z+ooh/EqD5eT/WeV/906ubZV6Y N9syiaH791H/2PMnrS0SLigMl335bYJeCeRmEqh7ZKpvJnAGGqVFI3Qegl6Tci5D/+1S XZCRgHKkL8AqsFebDDz1o3mCyNew4SWy5dmNdqifDucQrONyW8yKW6AQxoj77gyBrPQf kJhMkJ/oMIheCZt5BmH7gZuwkQ/FtmZ7v+4ZZ8hg6hm8fAyId+zj8rNhVaseO3QcwNYp vwE6j6tkaO5Tjm0J2iWupxiz8jQdeIAS9r5yb7Li8yioEqnj+fzRJnUsP5F8d588CFOo 4I6w== 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.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 01:49:10 -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:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,374,1526367600"; d="scan'208";a="76038339" Received: from yhuang6-ux31a.sh.intel.com ([10.239.195.246]) by orsmga002.jf.intel.com with ESMTP; 19 Jul 2018 01:49:07 -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 , Dan Williams , Daniel Jordan Subject: [PATCH v3 8/8] swap, put_swap_page: Share more between huge/normal code path Date: Thu, 19 Jul 2018 16:48:42 +0800 Message-Id: <20180719084842.11385-9-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 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: 24123 2004 340 26467 6763 mm/swapfile.o unified: 24485 2004 340 26829 68cd mm/swapfile.o Dig on step deeper with `size -A mm/swapfile.o` for base and unified kernel and compare the result, yields, -.text 17723 0 +.text 17835 0 -.orc_unwind_ip 1380 0 +.orc_unwind_ip 1480 0 -.orc_unwind 2070 0 +.orc_unwind 2220 0 -Total 26686 +Total 27048 The total difference is the same. The text segment difference is much smaller: 112. More difference comes from the ORC unwinder segments: (1480 + 2220) - (1380 + 2070) = 250. If the frame pointer unwinder is used, this costs nothing. Signed-off-by: "Huang, Ying" Reviewed-by: 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 --- mm/swapfile.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index d313f7512d26..2fe2e93cee0e 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1284,8 +1284,8 @@ void put_swap_page(struct page *page, swp_entry_t entry) if (!si) return; + ci = lock_cluster_or_swap_info(si, offset); if (size == 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++) { @@ -1294,13 +1294,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); @@ -1311,12 +1307,16 @@ void put_swap_page(struct page *page, swp_entry_t entry) return; } } - if (size == 1 || free_entries) { - for (i = 0; i < size; i++, entry.val++) { - if (!__swap_entry_free(si, entry, SWAP_HAS_CACHE)) - free_swap_slot(entry); + for (i = 0; i < size; 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 == size - 1) + return; + lock_cluster_or_swap_info(si, offset); } } + unlock_cluster_or_swap_info(si, ci); } #ifdef CONFIG_THP_SWAP