Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp36870imm; Tue, 21 Aug 2018 23:02:57 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwTtBaB60+zROD/SpT/wMeI6eGcdOmLv+dj08PNa1lpyQvw+BDbQAEdPaBY41s93HlIqL1h X-Received: by 2002:a63:5350:: with SMTP id t16-v6mr49862985pgl.196.1534917777220; Tue, 21 Aug 2018 23:02:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534917777; cv=none; d=google.com; s=arc-20160816; b=bKH6OYoC7ZAbzEnHbyFpjcpNBeFI18wgAjEhzF7YA9o4y64i0S8cMm9su0+F6pkVPd j2RsNsBoxuTQ9tiZv8V0zOCaxVwBi6y2TlT+f9XKvuXewys/gCYaTZ3+5JLbbbCQjWYy cKj9ZpujGZJVzfmPC4BC2vX3zj6eEBj37sMjO17gmVwVyIxGzKHbdEToNTzmw7d5P3gN rFtrA6objGTv4h9L76kbL/QeOGrxDA6APlBMTHQ6VDVlbhI5KCISccgDfXL76DA+gkKQ bOwlwKYLDCK4wd8bY9fuXJUlwZNzf2cY2yjzLfFSqDoguVuwHj7baxAeGL4Ji0LguGOB v9DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=MQtEyXxZ1vRMeSyyXegCzOsE5Pyarvaimev5VP7caPQ=; b=ZHOFRj40tNpFUEsC1VrDhoqiTKlq/ZWPSYJ5wRoXxt5UChtgz8b6OM+LdrWn4r8g6S 68Hg+AIdLRU/qdXxd9pFW1ki7KrQKtcc90OVRue5umiQ7+fpdT73wQUBFbT8b6zeDVN8 tpnTPG5zH+c4I6FtFIfQp+bm94wg8eOFkIHgiK/o6xBYhQKleHf/l9RHeHT+HZNcj99A NV60xex6w8PZOwdXDsXKxG0MDyNs7Nc/NRiltzM9ipmZRcdUOOImDuoo1oOoD01KB9/o flqpO3/sEbrdJ5OKTtme4f/xJa2up9gFkrGGFRGlSELy/RuB2Sw/BhOAYNIHCjkvHzRa Uemw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=SXUzJLoq; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m61-v6si840640plb.296.2018.08.21.23.02.41; Tue, 21 Aug 2018 23:02:57 -0700 (PDT) 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=@gmail.com header.s=20161025 header.b=SXUzJLoq; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728154AbeHVJYz (ORCPT + 99 others); Wed, 22 Aug 2018 05:24:55 -0400 Received: from mail-yb0-f196.google.com ([209.85.213.196]:44452 "EHLO mail-yb0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728088AbeHVJYy (ORCPT ); Wed, 22 Aug 2018 05:24:54 -0400 Received: by mail-yb0-f196.google.com with SMTP id l16-v6so279314ybk.11 for ; Tue, 21 Aug 2018 23:01:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=MQtEyXxZ1vRMeSyyXegCzOsE5Pyarvaimev5VP7caPQ=; b=SXUzJLoqEkyWa1WYNNnJX2CJwuJcYW9sP2xSp3+AalH0jJxWNI6Y6bGlvjkQYFKWA8 B4Ra6IekWm4A+V/AQqIrZtWAuULZ6KiGkvytDomytdaWjlCwtkt6P1F7gQS0LHSILq/b D5SrfyzuR3fHORAqHzwZYPUCJYXTC5YwMsnfiEJgy4AiSy//1YwQ/rRvcAX9ELBalX/C gdoDqmcyX0qfp4iWJljYTerMYvUy7ULYWDxqkYMCml9bKRgZE8qXeT8UyOFcTIxNaiRX BM3j24iX099y1Pbpi6ZDhW+aXjMSOtfcWJ6WPXBHIGiPWZqXBstCRCmxelBXUZXafCZD zLlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=MQtEyXxZ1vRMeSyyXegCzOsE5Pyarvaimev5VP7caPQ=; b=rq3omKUJiHe2UmPCHhOQGoCA1LH1shNQaa93rBFyMesqmRAG53xhiwl5QGt7Mbia+0 3Q3WMUIb/w33uRw6R9XZjtDKILvIeo2ycsB8cVRTz6Pbex/q/OuAcOCgqCQtBpEdnPBx Ctr0UHlb0N4QUfyi67kRoJo2yVEA8Jh/53KG5SKORvmQWwLgKCI4eXUuhz3gf4xW8Oa6 c7r4d5r04GxA8xhmNKdEHkf/aXND/EpxQt+Md19F7izfGPTdQeYzXYbRFhkkI8+x1qeB 86nEVP9rm7dZYptPrhzmALsDR0N5fbWAj9pHAlCe+LR53rURFehUAbcgNrMfLlRzKI38 5pog== X-Gm-Message-State: AOUpUlEaFiR8gkUPP3Qjwdsof9h6/an1rrhzzocQsuiDZBMrfYsTRCdh kVVYLcY4zcj2RT/ogZWkOSUCC5QKYB0+Z+zil7k= X-Received: by 2002:a25:5092:: with SMTP id e140-v6mr14658328ybb.44.1534917691797; Tue, 21 Aug 2018 23:01:31 -0700 (PDT) MIME-Version: 1.0 References: <20180817231834.15959-1-guro@fb.com> <20180818012213.GA14115@bombadil.infradead.org> <20180821171555.GA16545@cmpxchg.org> In-Reply-To: <20180821171555.GA16545@cmpxchg.org> From: Konstantin Khlebnikov Date: Wed, 22 Aug 2018 09:01:19 +0300 Message-ID: Subject: Re: [PATCH RFC] mm: don't miss the last page because of round-off error To: Johannes Weiner Cc: Matthew Wilcox , Roman Gushchin , linux-mm@kvack.org, Linux Kernel Mailing List , kernel-team@fb.com, Andrew Morton , Michal Hocko , Tejun Heo , Rik van Riel Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 21, 2018 at 8:15 PM, Johannes Weiner wrote: > On Tue, Aug 21, 2018 at 08:11:44AM +0300, Konstantin Khlebnikov wrote: >> On Sat, Aug 18, 2018 at 4:22 AM, Matthew Wilcox wrote: >> > On Fri, Aug 17, 2018 at 04:18:34PM -0700, Roman Gushchin wrote: >> >> - scan = div64_u64(scan * fraction[file], >> >> - denominator); >> >> + if (scan > 1) >> >> + scan = div64_u64(scan * fraction[file], >> >> + denominator); >> > >> > Wouldn't we be better off doing a div_round_up? ie: >> > >> > scan = div64_u64(scan * fraction[file] + denominator - 1, denominator); >> > >> > although i'd rather hide that in a new macro in math64.h than opencode it >> > here. >> >> All numbers here should be up to nr_pages * 200 and fit into unsigned long. >> I see no reason for u64. If they overflow then u64 wouldn't help either. > > It is nr_pages * 200 * recent_scanned, where recent_scanned can be up > to four times of what's on the LRUs. That can overflow a u32 with even > small amounts of memory. Ah, this thing is inverted because it aims to proportional reactivation rate rather than the proportional pressure to reclaimable pages. That's not obvious. I suppose this should be in comment above it. Well, at least denominator should fit into unsigned long. So full 64/64 division is redundant.