From patchwork Tue Jul 17 00:55:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 10527855 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 E4542600D0 for ; Tue, 17 Jul 2018 00:56:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DAF9D285A5 for ; Tue, 17 Jul 2018 00:56:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF893286B4; Tue, 17 Jul 2018 00:56:09 +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 708A3285A5 for ; Tue, 17 Jul 2018 00:56:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 326BF6B0274; Mon, 16 Jul 2018 20:56:03 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2EF4A6B0275; Mon, 16 Jul 2018 20:56:03 -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 0939F6B0275; Mon, 16 Jul 2018 20:56:02 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f198.google.com (mail-pf0-f198.google.com [209.85.192.198]) by kanga.kvack.org (Postfix) with ESMTP id A9C236B0273 for ; Mon, 16 Jul 2018 20:56:02 -0400 (EDT) Received: by mail-pf0-f198.google.com with SMTP id j25-v6so26153493pfi.20 for ; Mon, 16 Jul 2018 17:56:02 -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=fvtkNq/NGKySs1jQRiaeP6hQdwsKl/NfvZvU20iCWoU=; b=t9Vh/AXCsmAO6EKffCgHXl/a9RwYylsc7SQQC3lKKY0jKe1Mcc90XvJvnnYI+5PMa7 iymyew3U9cTbiyX0VYE4t9Intztvk9t47vijzJwoiBvg8zpatLPwKXFdLOMcm4EEJidY fnp5Et7hDw4qKxDdZIN5pXy9rCS7LMRAoNH/XYI97i0WWVjXKn2IlXObqgx6b9D7R/Yj AnaUFaku7fKV9+dJPyrXlIlMbQTBX+BKeW9Djt6JLVIqrGaSxYrJeHphoxa0S8kgmKyr 6Sdgh3QzSG6HEnn3Z7UJtNM+zvj0b+zY0EHNZZEuXfBw1BEVbHSoLuboiJ/9bDiB8eRF qE9w== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.126 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: AOUpUlGSOZuYhNIMpz5mKZoARU3Mr6uBLgBjbn/xZuqFTTfol6/E8j0n JiDv2ahPc9X8nJKXMyG6aZ8mXKItSCAceDIZ+5eg8VXy8ZzNJEPm5Xw5s+dVYuX9RoamPbPZcG4 DQsh0E0ZdpcA8zwbkzAFcRyMZ8n2G+0rIxo1uFF6h0AwkjG2i2TlUxj4nmilVIaUhbA== X-Received: by 2002:a17:902:b903:: with SMTP id bf3-v6mr18334143plb.160.1531788962400; Mon, 16 Jul 2018 17:56:02 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdN6qG5axIQXyB/epyo4qnYcOlSOWkYAb9gBG16YoiU7j2zjoYm1/mX+hPM8O5QnsjoeoPx X-Received: by 2002:a17:902:b903:: with SMTP id bf3-v6mr18334112plb.160.1531788961672; Mon, 16 Jul 2018 17:56:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531788961; cv=none; d=google.com; s=arc-20160816; b=kbZ9bcjbEnsBIYpca8AGJzsy9l/o/B2Ny5jb4iKiV0ZBGBVmk/nfzb4i2Uj/qtPdlD e/w0oil4M1Wu5R9CfvsNT0jGB0m2QbyNeA9OJf0i2tl+hKUNbdfKnIntdeT/Z4XWwqb3 S+GSAjy0pgx76VRyqeCUPFvVNK4SoJwrKOGDg3aY/8xZLPotbotcRUFnlJPO5dHXIZtR FyyVMGeNxX887CPjzfIQurUgI7yQCds1FUZgw3jwmyNgQQTwwMMe7hxBpU48g1ygab0q adpfiQtB5rd8GCqqH7k+bOpk+5qxWQH0qTgsrS2GTSVvjTeYBRCv6sABNGNtM/VjLcAE x5Zw== 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=fvtkNq/NGKySs1jQRiaeP6hQdwsKl/NfvZvU20iCWoU=; b=U+jpM2HFCG9gpXM9/sbp60Wy3nlVBH7nUZ4JxBxWJGC8OxMXDm2wgwzKlfDalxWWDH QQLs4ihfnCeRwiopZUzAdufIRWRKic/nZBftcxWc/KVtfZKzWt1ce06qMe+4j6yOlAIt k7kQA3HHYghXU0/jNnICtWoJ4tlaLp3vGT3FG7QXAjzyCBz58QQFNqpTJutjH6zVyJUs U/eUl5N9quWSHWMYMB6vOzVqc6QHmIXbJOfQFw0/GnbXqKGZJU8u6s97Fwd202JVKqp6 X+JUguXnWg9ZWTSV05GCisa7zwCBUjuGCu6PqtMOI1OsuQ46cC0rLHmelRVXUNoP1t1k aqkQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga18.intel.com (mga18.intel.com. [134.134.136.126]) by mx.google.com with ESMTPS id bc5-v6si30619643plb.413.2018.07.16.17.56.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Jul 2018 17:56:01 -0700 (PDT) Received-SPF: pass (google.com: domain of ying.huang@intel.com designates 134.134.136.126 as permitted sender) client-ip=134.134.136.126; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.126 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 fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Jul 2018 17:56:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,363,1526367600"; d="scan'208";a="245788312" Received: from yhuang6-ux31a.sh.intel.com ([10.239.197.184]) by fmsmga005.fm.intel.com with ESMTP; 16 Jul 2018 17:55:59 -0700 From: "Huang, Ying" To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Dave Hansen , Michal Hocko , Johannes Weiner , Shaohua Li , Hugh Dickins , Minchan Kim , Rik van Riel , Daniel Jordan , Dan Williams Subject: [PATCH v2 7/7] swap, put_swap_page: Share more between huge/normal code path Date: Tue, 17 Jul 2018 08:55:56 +0800 Message-Id: <20180717005556.29758-8-ying.huang@intel.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180717005556.29758-1-ying.huang@intel.com> References: <20180717005556.29758-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: 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 fec28f6c05b0..cd75f449896b 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