From patchwork Tue Nov 20 08:54:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 10689985 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5EDDE13AD for ; Tue, 20 Nov 2018 08:55:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 50D5E2991D for ; Tue, 20 Nov 2018 08:55:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4478629CA2; Tue, 20 Nov 2018 08:55: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=ham 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 00CFF2991D for ; Tue, 20 Nov 2018 08:55:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 09D4D6B1F33; Tue, 20 Nov 2018 03:55:03 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F3E016B1F34; Tue, 20 Nov 2018 03:55:02 -0500 (EST) 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 E4E8F6B1F35; Tue, 20 Nov 2018 03:55:02 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by kanga.kvack.org (Postfix) with ESMTP id 979AF6B1F33 for ; Tue, 20 Nov 2018 03:55:02 -0500 (EST) Received: by mail-pg1-f197.google.com with SMTP id 202so849967pgb.6 for ; Tue, 20 Nov 2018 00:55:02 -0800 (PST) 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=N19UD6cLHtC6p5LOEKZov7bPAn77ZKnzMG00MJGQCdE=; b=JozRlwYxCx3r/KAA4hZtcyj14XW/TTg7YZ0Po3Xzzuk6vkHv8hRlrLKXWDfnYbwB4S tmWL32goD/KyGFEkxr/6Q8engW0GHwseFCVhKFxPB9AtWKqy5XgzJxct9Rj6awnwOmQQ kncJ5M16ZoI/rjSLi5sNQieo7Ceo25D07WzJv9Uj3F6u3LCeicQ0Qcy18gm/Q9Suv9To DBG0nqcOXdCMjb76/OzqoJSPaXLtQ29HZu02+uYK22qHGkDxMufkxrkUGn3idp1bgfYQ S38BefpFaTZFZWYMlf+HCHJ3yAJYX41jRVTj8s+vZzXgDNkdxffzl828Yzxla1D8y18/ Z7gw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 192.55.52.88 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: AA+aEWaU4kx4Rxn2sx/8zGj0QE/e8AITR/LCFcot+BPtfPsGFWwpUY74 OqBiW2v1J44yJWKNseopqIWZPeArbUPAq3jN65EkMZDuMriuNFRccu0a3fOcalLw5JHci8G0ubV SzLqlg1SHRbhzKV9Aj/5qfwKfVvhftz1olyshGGaf3UE7EDs41px2AnUP1V+1yNDoaQ== X-Received: by 2002:a63:2447:: with SMTP id k68-v6mr1109545pgk.156.1542704102276; Tue, 20 Nov 2018 00:55:02 -0800 (PST) X-Google-Smtp-Source: AFSGD/VO3ZEQJYN1KcWEjXOqiPEmAkxyE7FiSjS+rDvZVmatIjFLHnGkw0J6EMIEb+OFvHJY97EZ X-Received: by 2002:a63:2447:: with SMTP id k68-v6mr1109500pgk.156.1542704101067; Tue, 20 Nov 2018 00:55:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542704101; cv=none; d=google.com; s=arc-20160816; b=O5iUdJR+3LYRl4reSVofqrwNEQVVOnyfrqDpIrZV0M29JI/LaUN0n52OhyJGOj02GV P3J+Zh3LdOmkpOEllv5QPITkz0MoWNMI60IvkblwooXRu9WuCA8qDHQOwk0FLUXy9loR BQ31ankYxfx5QNGlHMNx2nmEjzSdpqsGh17euisAI/Pk0Sgu2nSVRTjpUy4HgEKYKoXX qFW1eBSV+kUTlf/YNLEawNDzS7Ebcq66fGa6B7oc/yRVXtGIAA9ztvi3vX0/bURufcT+ xFAd+H6MoF1Pz/ChHpuxOUMRlbkKbfRfe1sIklzo31vvOP0uwp9YiNzddrWY41w0f0k6 vEzA== 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; bh=N19UD6cLHtC6p5LOEKZov7bPAn77ZKnzMG00MJGQCdE=; b=cme3oMNkOIo27sk9YVAy0esrr8jyAdH48UfBNrai5Hk0UYVuDgKbevX0dcuJousjEe RAne0+/EhgjeWs1RGTJcnpFP9ifEGF0qouqy/mdqBI3I6zmNW+760ffRG39E+F/kbs34 yG1K9Vf1ooxmYKBpvyQk+jD/b0SicjZTY8WyY07FMWsZs3ulIFtHXgDCpkrqJT6sEUyJ oFGqx6nqoX9FIOYsbjI33ChK0ZsGF+Hkd3fOlUD+CXDtLBqmXwyVjGtTjhoc3ANf0RFm eEWrtInWUANP9BWMjgKnpmSmNdq8cZ+bwz9UgsuBdVycjQosIs27xPXprUsVgoPZMF/z N6aw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 192.55.52.88 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga01.intel.com (mga01.intel.com. [192.55.52.88]) by mx.google.com with ESMTPS id b15si24149550plm.431.2018.11.20.00.55.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 00:55:01 -0800 (PST) Received-SPF: pass (google.com: domain of ying.huang@intel.com designates 192.55.52.88 as permitted sender) client-ip=192.55.52.88; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 192.55.52.88 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 fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Nov 2018 00:55:00 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,256,1539673200"; d="scan'208";a="106105741" Received: from yhuang-mobile.sh.intel.com ([10.239.197.245]) by fmsmga002.fm.intel.com with ESMTP; 20 Nov 2018 00:54:57 -0800 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , "Kirill A. Shutemov" , Andrea Arcangeli , Michal Hocko , Johannes Weiner , Shaohua Li , Hugh Dickins , Minchan Kim , Rik van Riel , Dave Hansen , Naoya Horiguchi , Zi Yan , Daniel Jordan Subject: [PATCH -V7 RESEND 02/21] swap: Add __swap_duplicate_locked() Date: Tue, 20 Nov 2018 16:54:30 +0800 Message-Id: <20181120085449.5542-3-ying.huang@intel.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20181120085449.5542-1-ying.huang@intel.com> References: <20181120085449.5542-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 The part of __swap_duplicate() with lock held is separated into a new function __swap_duplicate_locked(). Because we will add more logic about the PMD swap mapping into __swap_duplicate() and keep the most PTE swap mapping related logic in __swap_duplicate_locked(). Just mechanical code refactoring, there is no any functional change in this patch. Signed-off-by: "Huang, Ying" Cc: "Kirill A. Shutemov" Cc: Andrea Arcangeli Cc: Michal Hocko Cc: Johannes Weiner Cc: Shaohua Li Cc: Hugh Dickins Cc: Minchan Kim Cc: Rik van Riel Cc: Dave Hansen Cc: Naoya Horiguchi Cc: Zi Yan Cc: Daniel Jordan --- mm/swapfile.c | 63 ++++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index ec210be02c3b..f3c175d830b1 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3441,32 +3441,12 @@ void si_swapinfo(struct sysinfo *val) spin_unlock(&swap_lock); } -/* - * Verify that a swap entry is valid and increment its swap map count. - * - * Returns error code in following case. - * - success -> 0 - * - swp_entry is invalid -> EINVAL - * - swp_entry is migration entry -> EINVAL - * - swap-cache reference is requested but there is already one. -> EEXIST - * - swap-cache reference is requested but the entry is not used. -> ENOENT - * - swap-mapped reference requested but needs continued swap count. -> ENOMEM - */ -static int __swap_duplicate(swp_entry_t entry, unsigned char usage) +static int __swap_duplicate_locked(struct swap_info_struct *p, + unsigned long offset, unsigned char usage) { - struct swap_info_struct *p; - struct swap_cluster_info *ci; - unsigned long offset; unsigned char count; unsigned char has_cache; - int err = -EINVAL; - - p = get_swap_device(entry); - if (!p) - goto out; - - offset = swp_offset(entry); - ci = lock_cluster_or_swap_info(p, offset); + int err = 0; count = p->swap_map[offset]; @@ -3476,12 +3456,11 @@ static int __swap_duplicate(swp_entry_t entry, unsigned char usage) */ if (unlikely(swap_count(count) == SWAP_MAP_BAD)) { err = -ENOENT; - goto unlock_out; + goto out; } has_cache = count & SWAP_HAS_CACHE; count &= ~SWAP_HAS_CACHE; - err = 0; if (usage == SWAP_HAS_CACHE) { @@ -3508,11 +3487,39 @@ static int __swap_duplicate(swp_entry_t entry, unsigned char usage) p->swap_map[offset] = count | has_cache; -unlock_out: +out: + return err; +} + +/* + * Verify that a swap entry is valid and increment its swap map count. + * + * Returns error code in following case. + * - success -> 0 + * - swp_entry is invalid -> EINVAL + * - swp_entry is migration entry -> EINVAL + * - swap-cache reference is requested but there is already one. -> EEXIST + * - swap-cache reference is requested but the entry is not used. -> ENOENT + * - swap-mapped reference requested but needs continued swap count. -> ENOMEM + */ +static int __swap_duplicate(swp_entry_t entry, unsigned char usage) +{ + struct swap_info_struct *p; + struct swap_cluster_info *ci; + unsigned long offset; + int err = -EINVAL; + + p = get_swap_device(entry); + if (!p) + goto out; + + offset = swp_offset(entry); + ci = lock_cluster_or_swap_info(p, offset); + err = __swap_duplicate_locked(p, offset, usage); unlock_cluster_or_swap_info(p, ci); + + put_swap_device(p); out: - if (p) - put_swap_device(p); return err; }