• Guoqing Jiang's avatar
    RDMA/rtrs-srv: Don't guard the whole __alloc_srv with srv_mutex · d715ff8a
    Guoqing Jiang authored
    The purpose of srv_mutex is to protect srv_list as in put_srv, so no need
    to hold it when allocate memory for srv since it could be time consuming.
    
    Otherwise if one machine has limited memory, rsrv_close_work could be
    blocked for a longer time due to the mutex is held by get_or_create_srv
    since it can't get memory in time.
    
      INFO: task kworker/1:1:27478 blocked for more than 120 seconds.
            Tainted: G           O    4.14.171-1-storage #4.14.171-1.3~deb9
      "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
      kworker/1:1     D    0 27478      2 0x80000000
      Workqueue: rtrs_server_wq rtrs_srv_close_work [rtrs_server]
      Call Trace:
       ? __schedule+0x38c/0x7e0
       schedule+0x32/0x80
       schedule_preempt_disabled+0xa/0x10
       __mutex_lock.isra.2+0x25e/0x4d0
       ? put_srv+0x44/0x100 [rtrs_server]
       put_srv+0x44/0x100 [rtrs_server]
       rtrs_srv_close_work+0x16c/0x280 [rtrs_server]
       process_one_work+0x1c5/0x3c0
       worker_thread+0x47/0x3e0
       kthread+0xfc/0x130
       ? trace_event_raw_event_workqueue_execute_start+0xa0/0xa0
       ? kthread_create_on_node+0x70/0x70
       ret_from_fork+0x1f/0x30
    
    Let's move all the logics from __find_srv_and_get and __alloc_srv to
    get_or_create_srv, and remove the two functions. Then it should be safe
    for multiple processes to access the same srv since it is protected with
    srv_mutex.
    
    And since we don't want to allocate chunks with srv_mutex held, let's
    check the srv->refcount after get srv because the chunks could not be
    allocated yet.
    
    Fixes: 9cb83748 ("RDMA/rtrs: server: main functionality")
    Link: https://lore.kernel.org/r/20201023074353.21946-6-jinpu.wang@cloud.ionos.comSigned-off-by: default avatarGuoqing Jiang <guoqing.jiang@cloud.ionos.com>
    Signed-off-by: default avatarJack Wang <jinpu.wang@cloud.ionos.com>
    Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
    d715ff8a
rtrs-srv.c 53.8 KB