Received: by 10.213.65.68 with SMTP id h4csp2113660imn; Thu, 29 Mar 2018 18:23:17 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+X/gIHKOG+6cjWX3/6b6kRpExcYT8uEfOZzne4mJgVXFZ2Cn3aN7m40qUbL2H2TrMX/+3c X-Received: by 10.98.206.77 with SMTP id y74mr8196414pfg.205.1522372997189; Thu, 29 Mar 2018 18:23:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522372997; cv=none; d=google.com; s=arc-20160816; b=vbDVTWUzM6LHDxAUzmuF5CUThXE28Dwm9opN3felMOKid2kXzJ9hSiAebODC0MzEZJ NflvbKpri9uU3qBqU9z67j9sJl/71ItsEgiOkyy5uZh8yXPnTm+AdiO1zQ70oxzFgkaH meGYDOjSuDFmVfeZg1IJWPcfjB0EylVXbZhMYT1fO4bUtg0pVCuQhm5gIVuPy5d6lDz1 LfX1zy42UI53aAdzSpKirWg/i0iZFXjHQYGQvvh3k+zENsspxKBrzkp+/Wem4OaqWVA9 LAWuqnl/jqZlH5aIUXtNL3VWhn9TPV+lqrjQw6g8qEFEPxk3CfQmTko+uCjsqeGyfSyj P0tA== 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:cc:to:subject :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:arc-authentication-results; bh=DfDwSFT92W0uDHRkSOpHnaHbYPu2+zy8XVfW+rnmczo=; b=EdTG9mV8zhd1RRAJOIgPWwNq34Jkr95TzOYVeAtgg8wR+pvCVEb6QEGhRFqyl8WOJ/ Eky8Kt6BGZIgeT0l+cyqW15Uj47aNeJStLhFceY0w49u1NM+hRqjLZ6BbRU3lPlZs8AQ oyRFjCpEUl1WYJiTZC47NCAflqf20hLdeSIBowOp8IDYcuemBArrgP5O3kmjlCO0BibV b2sw0c6qW5XIny3QAmwMyhdEZ14gEd5fm3ju2l3WmRyO1alR4wbIe77VhTtPzLOyP2RA 7tzTCiJFGj2A8ZhO91MridtAawajgo92W0YczAKqB1EoPqIdOg1V+Os658m+9TSlWd96 PQmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=iChwHZ/P; 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 p64si5353667pfd.393.2018.03.29.18.23.03; Thu, 29 Mar 2018 18:23:17 -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=iChwHZ/P; 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 S1752269AbeC3BV6 (ORCPT + 99 others); Thu, 29 Mar 2018 21:21:58 -0400 Received: from mail-io0-f196.google.com ([209.85.223.196]:38093 "EHLO mail-io0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751215AbeC3BV4 (ORCPT ); Thu, 29 Mar 2018 21:21:56 -0400 Received: by mail-io0-f196.google.com with SMTP id b20so9683128iof.5 for ; Thu, 29 Mar 2018 18:21:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=DfDwSFT92W0uDHRkSOpHnaHbYPu2+zy8XVfW+rnmczo=; b=iChwHZ/PR8Ny9D3+SqFeXYTibxTONzEbpgGi05O/Kbm/fMO0cGSTmddNvPtujT6ZZi AG4rJvZ3nLLSA3/+1dbomDUyi4WUvmwbAsNLpZeafjL2GaPO09kC7DL375E+neMY/9Ir t2FmUOGJFMThdkQQa4ItUCotMzMZD/d+oM+7LaPS3k0ccFc5odF4d8TA7TC6f3BZxmdQ sSuhRabe7HIKMCvvZ4Y0cDm5xqQScCP8zxDXAq9VFp0Dk7J0c5XE2l5ndzufHzXtqZNF wpkZUSw0tSjoamTdHZuGOsFjyYUBaMm/o/fH7zaXM6EC5GT3BwRQNgIOOEz/j3jJdg+s xi/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=DfDwSFT92W0uDHRkSOpHnaHbYPu2+zy8XVfW+rnmczo=; b=HHvjluzqbVWHajMEOQ2F0Lh/8SR6xiwcRRc+/rZwCKw5PD99ESIHRfCN9udKY3ELxG EBFv0jFPSi6m6wYT8ig1YMkPRG5Ke1mVC9RvBGqm4UVSgfvw7LQdk1fKtPgYcAwoE7b6 SS+Wq5vWwX+bS07vsGea3hGyTSGkQnCqLIPnR83N1z/pP9YYoLT/ypUH35/QARS00Cqr Frt9r/m+8SWy3zI0G8bliatVvDyQqIO1ygDCnQEV/8bms6cYyWTiezM9UxAPDNTQmFse 78njtHowpElfV5yFxuGqXuTIIWBtDbkTN3uPhsAF8jAN0yNZFTZ7XK7PsSYbhAQ/GCr0 08vw== X-Gm-Message-State: AElRT7HK0i4+cKEkGt30FoKFLln1/nit2gZnm1igUe6+iTCw3BbW98eX Ci2daqGZBEt3awffx/CDDuQKlLLIEac6E6u5Ea4= X-Received: by 10.107.57.133 with SMTP id g127mr28391626ioa.52.1522372916159; Thu, 29 Mar 2018 18:21:56 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.168.153 with HTTP; Thu, 29 Mar 2018 18:21:55 -0700 (PDT) In-Reply-To: <20180329065424.203172-1-minchan@kernel.org> References: <20180329065424.203172-1-minchan@kernel.org> From: Ganesh Mahendran Date: Fri, 30 Mar 2018 09:21:55 +0800 Message-ID: Subject: Re: [PATCH v5] ANDROID: binder: change down_write to down_read To: Minchan Kim Cc: LKML , Joe Perches , =?UTF-8?B?QXJ2ZSBIasO4bm5ldsOlZw==?= , Todd Kjos , Greg Kroah-Hartman , Martijn Coenen Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2018-03-29 14:54 GMT+08:00 Minchan Kim : > binder_update_page_range needs down_write of mmap_sem because > vm_insert_page need to change vma->vm_flags to VM_MIXEDMAP unless > it is set. However, when I profile binder working, it seems > every binder buffers should be mapped in advance by binder_mmap. > It means we could set VM_MIXEDMAP in binder_mmap time which is > already hold a mmap_sem as down_write so binder_update_page_range > doesn't need to hold a mmap_sem as down_write. > > Android suffers from mmap_sem contention so let's reduce mmap_sem > down_write. Hi, Minchan: It seems there is performance regression of this patch. Do you have some test result of android app launch time or binderThroughput= ? Thanks. > > Cc: Joe Perches > Cc: Arve Hj=C3=B8nnev=C3=A5g > Cc: Todd Kjos > Cc: Greg Kroah-Hartman > Reviewed-by: Martijn Coenen > Signed-off-by: Minchan Kim > --- > From v4: > * Fix typo and VM flags clear handling - Joe > > From v3: > * Fix typo > > From v2: > * Fix vma->flag setting - Arve > > From v1: > * remove WARN_ON_ONCE - Greg > * add reviewed-by - Martijn > > Martijn, I took your LGTM of v1 as Reviewed-by. If you don't like it > or want to change it to acked-by, please, tell me. > > drivers/android/binder.c | 4 +++- > drivers/android/binder_alloc.c | 6 +++--- > 2 files changed, 6 insertions(+), 4 deletions(-) > > diff --git a/drivers/android/binder.c b/drivers/android/binder.c > index 764b63a5aade..bb63e3b54e0c 100644 > --- a/drivers/android/binder.c > +++ b/drivers/android/binder.c > @@ -4722,7 +4722,9 @@ static int binder_mmap(struct file *filp, struct vm= _area_struct *vma) > failure_string =3D "bad vm_flags"; > goto err_bad_arg; > } > - vma->vm_flags =3D (vma->vm_flags | VM_DONTCOPY) & ~VM_MAYWRITE; > + vma->vm_flags |=3D VM_DONTCOPY | VM_MIXEDMAP; > + vma->vm_flags &=3D ~VM_MAYWRITE; > + > vma->vm_ops =3D &binder_vm_ops; > vma->vm_private_data =3D proc; > > diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_allo= c.c > index 5a426c877dfb..4f382d51def1 100644 > --- a/drivers/android/binder_alloc.c > +++ b/drivers/android/binder_alloc.c > @@ -219,7 +219,7 @@ static int binder_update_page_range(struct binder_all= oc *alloc, int allocate, > mm =3D alloc->vma_vm_mm; > > if (mm) { > - down_write(&mm->mmap_sem); > + down_read(&mm->mmap_sem); > vma =3D alloc->vma; > } > > @@ -288,7 +288,7 @@ static int binder_update_page_range(struct binder_all= oc *alloc, int allocate, > /* vm_insert_page does not seem to increment the refcount= */ > } > if (mm) { > - up_write(&mm->mmap_sem); > + up_read(&mm->mmap_sem); > mmput(mm); > } > return 0; > @@ -321,7 +321,7 @@ static int binder_update_page_range(struct binder_all= oc *alloc, int allocate, > } > err_no_vma: > if (mm) { > - up_write(&mm->mmap_sem); > + up_read(&mm->mmap_sem); > mmput(mm); > } > return vma ? -ENOMEM : -ESRCH; > -- > 2.17.0.rc1.321.gba9d0f2565-goog >