Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2153773imu; Sun, 18 Nov 2018 17:13:05 -0800 (PST) X-Google-Smtp-Source: AJdET5cwpeHEMbu3uILxMDZMeP7HuY+kciYikX4ERAq6Pa5TfGy83vD/qVqRr69b+ukxzIZjIJIy X-Received: by 2002:a63:64c:: with SMTP id 73mr18152991pgg.373.1542589985649; Sun, 18 Nov 2018 17:13:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542589985; cv=none; d=google.com; s=arc-20160816; b=ii3QU87lbybVkOzP9T7r9rhFpykcNfABhhVrtGZHi9M+YZKOPERby8Eypg2xv5Eg8J 72+0tzPCFTbRtSMXbocfca1KP0XzebKpPTe4ZeaH/QKe9E2AvLVlyR0VCz0Bpc0G3Z55 CVK1PxIgFan4Rpif3+5dLWfYyVTnuD8QoekO9Zc2n9F1K0cwd+ZJKgyxjUJhsRwOu1fg dtLDAed/RIODyEajECZ5yedGCSAApPyVhxoSYlJIz4hhL9SK6F2bHbFqZQVBvF0ja9oT 6KjaXTRgNVDgvRhm1wOg2fSQiAE901M81Y7N0ZhoBJRBE+eifoVk0jHVAcyD6drNdtOO AV3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=08RTZHbHI+FX7DFs4z5QY980a6/oJNTmgmTtWQcGnR8=; b=I3EitTEj3asJitHtrsqF4OEa5ZXm1nCZ2UU4K4Vq5fxzR+yIPcZ7uWiKtXPkDqA2+6 JZmRMvcsH8Ex/Nj+vjI+9OMKpuab1bH8uk0MGJXZm9DY5CiDTXjccDck5QgLaygvNE/i fMxtVvjpl4BAMU6OitS2brUjOnmn227CKEMestWjha/tgg0lHGrLgnItVyD74m96L7Xl wezeKCpAXz999suWBp0eK6M4mNfBVPX6GOvBBcgoVRprvpYo13ugqMxxLmfxBZs5TjSG 06PHZbGMDjpDSXto4NZ+4H8ZzYMAg9Rct54wdNUvFx7/sx/4xGfus548tB/Esu6tczHM xFrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=gWjOa9pr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x186-v6si41858711pfx.94.2018.11.18.17.12.50; Sun, 18 Nov 2018 17:13:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=gWjOa9pr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727168AbeKSLb3 (ORCPT + 99 others); Mon, 19 Nov 2018 06:31:29 -0500 Received: from mail-it1-f195.google.com ([209.85.166.195]:55758 "EHLO mail-it1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725947AbeKSLb2 (ORCPT ); Mon, 19 Nov 2018 06:31:28 -0500 Received: by mail-it1-f195.google.com with SMTP id o19so5820596itg.5 for ; Sun, 18 Nov 2018 17:09:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=08RTZHbHI+FX7DFs4z5QY980a6/oJNTmgmTtWQcGnR8=; b=gWjOa9przldWulueeHOQsEz8sDSUpPVukBSbfAD00DxaLIJfMa6bbEbn7CC5BgIDxL gLm8uqvTQBvZDJx/bHHEsrpM/pMWr/9ZSl998FlZLudlOaRh/2WcCWKLHGG+ASm51eNB XT+DU8J6JplI1A6vNifzM0YgGfEyk6CSv7CQ9s+/ZFQhjZykV5rU8MQX7v7QRe8eoQT2 TW5jbOyY7NHA+m3WIqJROC9YyKN6aG46JdxfS6Uh5ed603q8xM+QBb+kwFurrbNCDgVL Whqercs6blapAX2SZe/KPM4GpzGT5xrk3IFfzHwsaKSKEmBd8hzKH3h6RhNYdKBoqA5r HEMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=08RTZHbHI+FX7DFs4z5QY980a6/oJNTmgmTtWQcGnR8=; b=EN8aDcbVuUJUVd/fLOo2unKn1bdQBtJDpXzNjm+3WRnAwLL4ERucKvqyL5UndByyiE pe25JT/Nv0KgsbXumKoErBOuxTel0wgauMoBXpbeCJJYxoTlr0hBxM2XGFBUcuP4/pGD 5tg5vVHlc4y/yl8xV2U9DLL5efU4gMKPhpeFe0RM7SmmWtJ6UImzf8WoLqWZcka2iBO2 L3rquEXtErfyRZoyFirruszgFcC/mDfjU6MGKazdd7kLg48XEwsDHRHoqCVm3vdsf7gM j2kMuXkAfD7wTwqDr+Btkilh05LnUnK/0Blbp+lmjlKRyJozS2vDIGQOwDYlAKQhvOsf dkvQ== X-Gm-Message-State: AA+aEWZN5IA29ZMe4JTRC7SDHsaS8D94wULdtLm4JkeCtDYtFuX1kNUN cS9PskfHRLVB1Chq/2gM9dJlAg== X-Received: by 2002:a24:3796:: with SMTP id r144-v6mr6481688itr.79.1542589773265; Sun, 18 Nov 2018 17:09:33 -0800 (PST) Received: from yuzhao.bld.corp.google.com ([2620:15c:183:0:a0c3:519e:9276:fc96]) by smtp.gmail.com with ESMTPSA id t196-v6sm13946809ita.30.2018.11.18.17.09.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 18 Nov 2018 17:09:31 -0800 (PST) From: Yu Zhao To: Hugh Dickins Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yu Zhao Subject: [PATCH v2] mm: fix swap offset when replacing shmem page Date: Sun, 18 Nov 2018 18:09:24 -0700 Message-Id: <20181119010924.177177-1-yuzhao@google.com> X-Mailer: git-send-email 2.19.1.1215.g8438c0b245-goog In-Reply-To: <20181119004719.156411-1-yuzhao@google.com> References: <20181119004719.156411-1-yuzhao@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We used to have a single swap address space with swp_entry_t.val as its radix tree index. This is not the case anymore. Now Each swp_type() has its own address space and should use swp_offset() as radix tree index. Signed-off-by: Yu Zhao --- mm/shmem.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index d44991ea5ed4..685faa3e0191 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1509,11 +1509,13 @@ static int shmem_replace_page(struct page **pagep, gfp_t gfp, { struct page *oldpage, *newpage; struct address_space *swap_mapping; - pgoff_t swap_index; + swp_entry_t entry; int error; + VM_BUG_ON(!PageSwapCache(*pagep)); + oldpage = *pagep; - swap_index = page_private(oldpage); + entry.val = page_private(oldpage); swap_mapping = page_mapping(oldpage); /* @@ -1532,7 +1534,7 @@ static int shmem_replace_page(struct page **pagep, gfp_t gfp, __SetPageLocked(newpage); __SetPageSwapBacked(newpage); SetPageUptodate(newpage); - set_page_private(newpage, swap_index); + set_page_private(newpage, entry.val); SetPageSwapCache(newpage); /* @@ -1540,7 +1542,8 @@ static int shmem_replace_page(struct page **pagep, gfp_t gfp, * a nice clean interface for us to replace oldpage by newpage there. */ xa_lock_irq(&swap_mapping->i_pages); - error = shmem_replace_entry(swap_mapping, swap_index, oldpage, newpage); + error = shmem_replace_entry(swap_mapping, swp_offset(entry), + oldpage, newpage); if (!error) { __inc_node_page_state(newpage, NR_FILE_PAGES); __dec_node_page_state(oldpage, NR_FILE_PAGES); -- 2.19.1.1215.g8438c0b245-goog