From patchwork Wed Sep 12 00:43:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 10596523 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 D4F926CB for ; Wed, 12 Sep 2018 00:44:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C22BC29AC1 for ; Wed, 12 Sep 2018 00:44:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B1C3C29AD2; Wed, 12 Sep 2018 00:44:14 +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 2057529AC1 for ; Wed, 12 Sep 2018 00:44:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0BEAC8E0004; Tue, 11 Sep 2018 20:44:13 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 046298E0001; Tue, 11 Sep 2018 20:44:12 -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 E2A5B8E0004; Tue, 11 Sep 2018 20:44:12 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by kanga.kvack.org (Postfix) with ESMTP id A0CB18E0001 for ; Tue, 11 Sep 2018 20:44:12 -0400 (EDT) Received: by mail-pl1-f200.google.com with SMTP id n4-v6so114268plk.7 for ; Tue, 11 Sep 2018 17:44:12 -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=PlULZszEr/zinic5XxLsYn/qt2WZkbM5AQ0JfYWFyu4=; b=W/gTwm7OwpPY3AH+zFeDViMulQWzHF5Tqr1GMvk6HV8AFtoFFPVzuHAHY/NgXr0TFl vxV8DMvAZRtHa2Vzyp73McRT3oXbWbHSjBwFMT4MelWNJ57clyG2FaYzyYOqlnVb0UsO +h5aLK7HR8kEZC7yZqhDJSyizmfdyEBlM3gtdcX3ufp1QVxXSP9KdfxafQGKlYtaVZaK wzkIWvaa8VYR00jx6XiRvg3wYIL8/2ubbgA9FJt9QqHYbAiqAXGVfULT4sUtrnjf67lo qnGiVPPzL0jNL3frWbVaHRXYu9aYV8iyeh/5c1+EJUvT2P3KzlhBw7/oo/7PmiKOPUTx 8+gw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.24 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: APzg51A2+razdpXDi/YZLsBGjv1MIYHfXJ3O7813Kk33DfjC7hkibVTf s4oS2/tSZHYGX0BF2H5KuPtQygMolgVVWzy8MKYFH9UuqoyEAAHy30KANAOs18sM22NDVUNyda3 LMueHWs9fNF+Xlc4EWYk3RvRUgCHyrzweqDPtXEjAtZFNoqcDLqlPjnf4LTKMZ8/n8w== X-Received: by 2002:a63:4c54:: with SMTP id m20-v6mr30919661pgl.292.1536713052334; Tue, 11 Sep 2018 17:44:12 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb85777eU3uIDFZjMPuy9+hap/e9fYqxDf7OagYO4FuJwCnKbOMpf9WQEbVPhXdNRQQTHaK X-Received: by 2002:a63:4c54:: with SMTP id m20-v6mr30919625pgl.292.1536713051605; Tue, 11 Sep 2018 17:44:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536713051; cv=none; d=google.com; s=arc-20160816; b=b19/3gQZPh5t4uMEi9O02kOQxK0UXbHi16dq/ts/OiyGQB8He6Sv1AEYCyh+v4wS3i Z3G0VJ1fkyXuOKvO/TL8eHMQK0GhyDsyezqzCJGjggn3HOpPkbSNZQcOs4oRymKL/pSV sZLvPdwUdxGmkdMaJyhETcmUs9E99X4HwLEPLNrKKI+3weI/0ubygMO+UkOJtZgV3roG U/qOEf5RPQ1IMUu+y+wiW5RxnT7b4mtUxwXMX69dzB7+RnVzjZtYyJk62WnWNZOWZeuI 1ErKBsai20A4BARkB8Px6bxTLe0tnW7hdRDUy3OLHkja4EMm3VXH208lDM5IWo3ptTrG 1sPA== 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=PlULZszEr/zinic5XxLsYn/qt2WZkbM5AQ0JfYWFyu4=; b=0ynb+y0ZIvKnzVLcx5VqS33R59y/sG+zS8uu093yYUgbV0q7lpig3V0wDjFqOYFaMx ruAWyE/Nsex+AUUPgQS/c+f0PRdbesQaLvkE9g3koDv3wnnBvyxMVTqJTj0SwKJua4kx wr0vhCVoB1ISY2qipYP15eg2SkV0x/raOcJ47l/ZnaRaTka/DOnX5cGEoRKDvV2G9qNj DfQ8SuA2hGY5PsHmfBPSaYCHaN+QQglQy7sxQ41Rp3Z+CrmSsxfOIi4tXKmicMv6t4ik D+CEi4RrMafnWt4+lp+mLXXmF0vAs8ZlNvImuB9mo4oLqyVcTq48GH+YgQVev94a0i1/ jG5A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga09.intel.com (mga09.intel.com. [134.134.136.24]) by mx.google.com with ESMTPS id p21-v6si20648717plq.338.2018.09.11.17.44.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Sep 2018 17:44:11 -0700 (PDT) Received-SPF: pass (google.com: domain of ying.huang@intel.com designates 134.134.136.24 as permitted sender) client-ip=134.134.136.24; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.24 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 fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Sep 2018 17:44:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,362,1531810800"; d="scan'208";a="69283805" Received: from unknown (HELO yhuang-mobile.sh.intel.com) ([10.239.198.87]) by fmsmga007.fm.intel.com with ESMTP; 11 Sep 2018 17:44:06 -0700 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 -V5 RESEND 02/21] swap: Add __swap_duplicate_locked() Date: Wed, 12 Sep 2018 08:43:55 +0800 Message-Id: <20180912004414.22583-3-ying.huang@intel.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180912004414.22583-1-ying.huang@intel.com> References: <20180912004414.22583-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 97a1bd1a7c9a..6a570ef00fa7 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3436,32 +3436,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]; @@ -3471,12 +3451,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) { @@ -3503,11 +3482,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; }