Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp269997imu; Mon, 26 Nov 2018 10:38:37 -0800 (PST) X-Google-Smtp-Source: AFSGD/W2cvSDGv1A/pwSFWnBkK8R2/zDzFlCT1phgQjzkS63sUNVXaVw1Vy0a+7aBeEyYmRR4wEI X-Received: by 2002:aa7:8286:: with SMTP id s6mr10220817pfm.63.1543257517771; Mon, 26 Nov 2018 10:38:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543257517; cv=none; d=google.com; s=arc-20160816; b=uCwlsSJT+a37kSwQgEuyw58zhwG/XRJmuHn5ko13+5lSDFLJjAxGT3K3SiwAW64N0G BPg6Xb3eB+hfuwt2cT0T2028BTLZLWRkVa9qjvshMKSwk6WJ8I+Rr9T9VmQm0fAaDyS/ hRxqvyjXJDRiFbzTe4KUgtE5Cl2bF4jRxBPgYlk74higQVowhHs6HfoJlSfP6hY8ek28 UhScIpZCXJZxWZRzCCD505cf8h/caOaI8vBE6D2txUaeOejXvTcDc4eiA6NBTXxnIojn Ko7pJOD0opj5B9qRIkrDyEanISuN1p8RNoIiV9MSWLLJWjGGhyqB3pOGANq+UbZ+k14+ hqVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=SDfbembJttLCvQaB/uw2uJ64x8/kRWuSrqsc/W7wU8s=; b=kEs+n7YmZHzqxJy+Ib7S0PO9c0jo9Ch7+5nn1iBnvrAn/Ux1hC4l3FCTdBHZdc1hzV 0X4b8fG0/yPXSJFpvqJ9eZWom471KyqGopZeF79Wp0u+LgLWDPcV9LX7RjflgsAeNE6v GyxyTYWY2TbWGcHJA78MwVhmcbOjhESFmSHKB4kXUkeApnbS5/K61gd6ZTmDvgRi5iMy hwDNcVxatk0nc6qZWk+xUpMk0q42KQ2NHvg5jMKBw1tv63wCPEjzBJv36KqIc1mzyrPK ZroRdBF6Hs9OuCDaae/qdjWlfUfqQG3vi3I8DzmnN6mrtmxWCGVbap+0psEimWFacesw OLnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@digitalocean.com header.s=google header.b=ZYLG7AZ1; 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=digitalocean.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c22si988738pgb.254.2018.11.26.10.37.55; Mon, 26 Nov 2018 10:38:37 -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=@digitalocean.com header.s=google header.b=ZYLG7AZ1; 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=digitalocean.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726397AbeK0Fab (ORCPT + 99 others); Tue, 27 Nov 2018 00:30:31 -0500 Received: from mail-qk1-f195.google.com ([209.85.222.195]:43963 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725747AbeK0Fab (ORCPT ); Tue, 27 Nov 2018 00:30:31 -0500 Received: by mail-qk1-f195.google.com with SMTP id r71so12908910qkr.10 for ; Mon, 26 Nov 2018 10:35:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=digitalocean.com; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=SDfbembJttLCvQaB/uw2uJ64x8/kRWuSrqsc/W7wU8s=; b=ZYLG7AZ1hPxXsx9mmzQtaFK3h/+vGycj8AbJGGbWq5sLZY0obthI8PJ9TTG+Mx7IiL 673AozXGa2nofwyQDxaSaBZ+0o64YLtViwp3Tv37HKnriWnXu7Jvzbxz6WUDviQCvhX9 xMu4AiZ3NYmzq+GpkgFsQk90E8X1Tim+V3xwc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=SDfbembJttLCvQaB/uw2uJ64x8/kRWuSrqsc/W7wU8s=; b=AvS8PUZCF43OlcvQ/cdhrk7sYF2DVZMsY9qR3MZawGcT21evLP1FSkz0u81fv+wCR5 iyqUT9iuZOJw+w81V/CaEd9mv782IqPv1w4mYzTOEqn7DxlPvKcDHZV26W0X3cpXamsV oSU3C8hzj/Cxqu4sySqhbuyHVnbChchrf6TO4KueR8tpPytf5NxUuSy94vM1Ok55YhIb aL/9UPQ54fI/rowjciTPevsO6wjdjCBCeq9zmPyu/oQPkvt8atuo4yr6LR9QpcmfyJy8 wM1cdpwEcMpfersAUVOjnN1uhy0QBfc4fK2tXdOeKmokJ5VruyVaLHzbdQExevTc8yvJ Q76g== X-Gm-Message-State: AA+aEWYDY8wE42KncvjIud/LQkxPDpICqjuNlOFo3avvSEtoIFN0JqhW 4Ncb96fcPCPVLBgA4CgfUe3shQ== X-Received: by 2002:a37:4b44:: with SMTP id y65mr25421147qka.316.1543257332941; Mon, 26 Nov 2018 10:35:32 -0800 (PST) Received: from [192.168.86.60] (c-24-147-95-226.hsd1.vt.comcast.net. [24.147.95.226]) by smtp.gmail.com with ESMTPSA id r142sm642876qke.27.2018.11.26.10.35.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Nov 2018 10:35:31 -0800 (PST) Subject: Re: [PATCH v2] mm: prototype: rid swapoff of quadratic complexity To: Matthew Wilcox Cc: Hugh Dickins , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Kelley Nielsen , Rik van Riel References: <20181126165521.19777-1-vpillai@digitalocean.com> <20181126172255.GK3065@bombadil.infradead.org> From: Vineeth Remanan Pillai Message-ID: <21acdf55-dbcb-1c8f-4783-9bb496dcbca3@digitalocean.com> Date: Mon, 26 Nov 2018 13:35:30 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20181126172255.GK3065@bombadil.infradead.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Mathew, Thanks for your response! On 11/26/18 12:22 PM, Matthew Wilcox wrote: > On Mon, Nov 26, 2018 at 04:55:21PM +0000, Vineeth Remanan Pillai wrote: >> + do { >> + XA_STATE(xas, &mapping->i_pages, start); >> + int i; >> + int entries = 0; >> + struct page *page; >> + pgoff_t indices[PAGEVEC_SIZE]; >> + unsigned long end = start + PAGEVEC_SIZE; >> >> + rcu_read_lock(); >> + xas_for_each(&xas, page, end) { > I think this is a mistake. You should probably specify ULONG_MAX for the > end. Otherwise if there are no swap entries in the first 60kB of the file, > you'll just exit. That does mean you'll need to check 'entries' for > hitting PAGEVEC_SIZE. Thanks for pointing this out. I shall fix this in the next version. > This seems terribly complicated. You run through i_pages, record the > indices of the swap entries, then go back and look them up again by > calling shmem_getpage() which calls the incredibly complex 300 line > shmem_getpage_gfp(). > > Can we refactor shmem_getpage_gfp() to skip some of the checks which > aren't necessary when called from this path, and turn this into a nice > simple xas_for_each() loop which works one entry at a time? I shall investigate this and make this simpler as you suggested. >> + list_for_each_safe(p, next, &shmem_swaplist) { >> + info = list_entry(p, struct shmem_inode_info, swaplist); > This could use list_for_each_entry_safe(), right? Yes, you are right. Will fix. Thanks, Vineeth >