diff --git a/src/userprog/syscall.c b/src/userprog/syscall.c index 015ebb7..6beac7d 100644 --- a/src/userprog/syscall.c +++ b/src/userprog/syscall.c @@ -406,7 +406,12 @@ syscall_close (int fd) unsigned fd_hash (const struct hash_elem *element, void *aux UNUSED) { - return hash_int (hash_entry (element, struct open_file, elem)->fd); + /* We use the FD as the hash value. This is because the FD is incremented + sequentially and is therefore unique for each file. It positively affects + the performance of the hash table: 1. It is unique so no need to call + expensive hash functions. 2. It being sequential means that the hash table + is more likely to be weight balanced. */ + return hash_entry (element, struct open_file, elem)->fd; } /* Comparator function for the open_file table. Compares two entries based on